美文网首页
UITextField添加到UIScrollView上,键盘消失

UITextField添加到UIScrollView上,键盘消失

作者: 乖乖Mor | 来源:发表于2017-10-26 16:54 被阅读0次

    由于scrollView  不会执行touch方法,所以给父控件self.view 加上一个 点击手势  在点击方法里加一个 [self.view endEditing]  也可以取消键盘

    界面消失的时候调用点击手势:[self tapGesture:_tapGesture];

    -(void)addGesture

    {

        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer     alloc]initWithTarget:self action:@selector(tapGesture:)];

        //点击所需的手指

        tapGesture.numberOfTouchesRequired = 1;

        //点击次数

        tapGesture.numberOfTapsRequired = 1;

        [self.view addGestureRecognizer:tapGesture];

        self.tapGesture=tapGesture;

    }

    -(void)tapGesture:(UITapGestureRecognizer*)gesture

    {

        [self.view endEditing:YES];

    }

    相关文章

      网友评论

          本文标题:UITextField添加到UIScrollView上,键盘消失

          本文链接:https://www.haomeiwen.com/subject/tcmkpxtx.html