【发布时间】:2018-05-12 14:03:09
【问题描述】:
我在一个屏幕中有 3 个视图,其中包含不同的组件,例如表格和按钮,当我尝试使用下面的代码关闭键盘时,当我单击包含 textView( 这就是我需要! ) 。但是,当我单击其他视图之一时,它会关闭。
下图显示了我拥有的视图,滚动视图中的最后一个视图是包含 textView 的视图。
尽管视图被录音,我怎样才能让键盘关闭。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
if(touch.phase == UITouchPhaseBegan) {
[aTextField resignFirstResponder];
}
}
此代码也无法关闭:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[self view] endEditing:TRUE];
}
【问题讨论】:
标签: ios objective-c keyboard