如何检测键盘何时显示和隐藏 [英] How to detect when keyboard is shown and hidden

查看:149
本文介绍了如何检测键盘何时显示和隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测键盘何时显示并隐藏在我的应用程序中?

How can I detect when the keyboard is shown and hidden from my application?

推荐答案

在您班级的ViewDidLoad方法中设置为收听有关键盘的消息:

In the ViewDidLoad method of your class set up to listen for messages about the keyboard:

// Listen for keyboard appearances and disappearances
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(keyboardDidShow:)
                                             name:UIKeyboardDidShowNotification
                                           object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardDidHide:)
                                             name:UIKeyboardDidHideNotification
                                           object:nil];

然后在你指定的方法中(在这种情况下 keyboardDidShow keyboardDidHide )你可以做点什么:

Then in the methods you specify (in this case keyboardDidShow and keyboardDidHide) you can do something about it:

- (void)keyboardDidShow: (NSNotification *) notif{
    // Do something here
}

- (void)keyboardDidHide: (NSNotification *) notif{
    // Do something here
}

这篇关于如何检测键盘何时显示和隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆