dahuichen 2013-05-18
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]; }