UITextField添加到UIScrollView上,键盘消失

2017-10-26  本文已影响0人  乖乖Mor

由于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];

}

上一篇下一篇

猜你喜欢

热点阅读