Featured

2014年3月29日星期六

This trick dismissed the keyboard, no matter which text field or textview is currently active.

1.  viewdidLoad


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

gestureRecognizer.cancelsTouchesInView = NO;

[self.navigationController.view addGestureRecognizer:gestureRecognizer];



2. 
- (void)hideKeyboard
{
// This trick dismissed the keyboard, no matter which text field or text
// view is currently active.
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
}

沒有留言:

發佈留言