//點選螢幕任何地方讓鍵盤消失
//點選螢幕任何地方讓鍵盤消失
- (void)setUpForDismissKeyboard {
NSNotificationCenter *nc = [NSNotificationCenterdefaultCenter];
UITapGestureRecognizer *singleTapGR =
[[UITapGestureRecognizeralloc] initWithTarget:self
action:@selector(tapAnywhereToDismissKeyboard:)];
NSOperationQueue *mainQuene =[NSOperationQueue
[nc addObserverForName:UIKeyboardWillShowNotification
object:nil
queue:mainQuene
usingBlock:^(NSNotification *note){
[self.viewaddGestureRecognizer:singleTapGR];
}];
[nc addObserverForName:UIKeyboardWillHideNotification
object:nil
queue
usingBlock:^(NSNotification *note){
[self.viewremoveGestureRecognizer:singleTapGR];
}];
}
//點選螢幕任何地方讓鍵盤消失
- (void)tapAnywhereToDismissKeyboard:(UIGestureRecognizer *)gestureRecognizer {
//此method會將self.view裡所有的subview的first responder都resign掉
[self
}