当前位置:网站首页>Uiscrollview add gestures show and hide keyboard

Uiscrollview add gestures show and hide keyboard

2022-06-24 02:30:00 Juming 12255

General idea : In itself textField Click the keyboard to pop up , After clicking the gesture, you view End edit , Gesture set to no, Click again textField The keyboard pops up , At this time, the notification gesture interaction is yes that will do

First, in the .h Add gesture protocol to the file <UIGestureRecognizerDelegate>

stay .m A gesture pointer is declared in the file

UITapGestureRecognizer * _gesture;

 _gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidesKeyboard)];     _gesture.enabled = NO;// The initial gesture is set to no     [self.view addGestureRecognizer:_gesture]; Method of hiding keyboard

- (void)hidesKeyboard{     [self.view endEditing:YES];     _gesture.enabled = NO; }

The keyboard shows that I used notification and gesture to

Register a notice first ,

[[NSNotificationCenter defaultCenter] addObserver:self                                              selector:@selector(keyboardWillShow)                                                  name:UIKeyboardWillShowNotification                                                object:nil]; The way to complete the notification is to set the gesture to yes that will do

- (void)keyboardWillShow {    _gesture.enabled = YES;

}

原网站

版权声明
本文为[Juming 12255]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/10/20211029122450508q.html

随机推荐