iOS点击键盘以外空白区域隐藏键盘的常见方法
iOS开发中,经常要用到输入框,可默认情况下,输入框出来之后,除非点击键盘上面的“Done”或“Next”按钮才能将其隐藏。站在用户体验的角度上看,这种情况很不友好,尤其是不能突显苹果操作的便捷性。因此,查阅了一些资料,加上实践,总结出了两种方法:
第一种,是最常见的,就是给最外层的view添加一个手势响应UITapGestureRecognizer,代码如下:
- (void)viewDidLoad { [super viewDidLoad]; UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)]; tapGr.cancelsTouchesInView = NO; [self.view addGestureRecognizer:tapGr]; } -(void)viewTapped:(UITapGestureRecognizer*)tapGr { [activitySearchBar resignFirstResponder]; }
相关推荐
WinerChopin 2020-06-12
inabaraku 2020-05-22
chenjinlong 2019-10-26
快看是Charlie 2019-08-22
82246839 2015-07-12
manifold 2015-06-22
internet我最爱 2014-10-29
lwpkjio 2014-10-29
nihuotuboliefu 2014-10-29
jltd00 2014-10-28
fish 2014-10-07
mobilechannel 2016-05-03
Cincan 2019-07-01
任玉刚 2019-06-27
ZhongGuanGuan 2014-10-31
zgjxyszh 2014-05-11
琴弦第七 2013-09-12