http://www.coneboy.com/?p=1180
1.遍历取消
当前视图上有多个uitextfield时,来隐藏键盘, 先遍历视图的所有子视图来 如果是UITextField就将其设为非第一响应 当然,如果要隐藏子视图上的UITextField的话可以进一步判断view的subviews的个数,如果大于1则遍历view的子视图,然后作类似操作
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
-
(
BOOL
)textFieldShouldBeginEditing
:
(UITextField
*
)textField
{ UITapGestureRecognizer *tapGestureRecognizer = [ [UITapGestureRecognizer alloc ] initWithTarget :self action : @selector (done : ) ]; tapGestureRecognizer.numberOfTapsRequired = 1; [self.view addGestureRecognizer : tapGestureRecognizer ]; //只需要点击非文字输入区域就会响应hideKeyBoard [tapGestureRecognizer release ]; return YES; } - ( void )done : ( id )sender { for (UIView *view in self.view.subviews ) { if ( [view isKindOfClass : [UITextField class ] ] ) { [view resignFirstResponder ]; } } } |
2.不需要遍历
1
|
[
[
[UIApplication sharedApplication
] keyWindow
] endEditing
:
YES
];
|
3.UIView 取消相应
1
|
[self.view endEditing
:
NO
]
|