iphone - 关闭 iPad 键盘

标签 iphone ios ipad keyboard

我正在为 iPhone 和 iPad 创建一个 iOS 应用程序,我的一些屏幕有 UITextFields。我希望在用户单击文本框时关闭键盘。为此,我编写了以下代码:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
     [firstName resignFirstResponder];
     [lastName resignFirstResponder];
     [email resignFirstResponder];
     [password resignFirstResponder];
     [retypePassword resignFirstResponder];
}

这适用于 iPhone,但不适用于 iPad 上的键盘。我在网上搜索过,所有的建议都不起作用。主要建议是:

- (BOOL)disablesAutomaticKeyboardDismissal {
       return NO;
}

但这还是不行? 任何帮助将不胜感激。

最佳答案

Add this method to .h file, 
-(IBAction)fn_resign:(id)sender;


Inherit your XIB to UIControl and just add following method to the view.

And in file's owner assign this method to view.

in .m:
-(IBAction)fn_resign:(id)sender{
   //Hide you keyboard.
}

关于iphone - 关闭 iPad 键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18381231/

相关文章:

iphone - 旋转带有缩放图像的动画

ios - SpriteKit CCFollow 替代方案?

iphone - 在 iOS 中创建播放列表?

ios - 没有签名证书 iOS 分发

iphone - iOS:日期组件查询

iphone - iOS初学者:字符串串联

iphone - 仅当强度达到一定分贝时才从语音输入中识别短语 [iOS]

iphone - 带有自定义 map 的 MapKit

javascript - iPhone/iPad 是否支持 mouseout 事件?

iphone - NSDate从字符串给出错误的结果