ios 如何判断键盘是否已经显示
2015-01-08 13:15
507 查看
在群里看到有人问:ios如何判断键盘已经显示在界面上。
其实这个解决很简单:
写一个单例来管理键盘的状态。
这个单例在初始化方法init种监听2个事件,分别是
UIKeyboardDidShowNotification(键盘弹出通知)和
UIKeyboardWillHideNotification (键盘消失通知 然后在相应的方法中设置一个属性就行了。
大致的实现如下:
-(id)init
{
self = [super init];
if (self)
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(keyboardDidShow) name:UIKeyboardDidShowNotification object:nil];
[center addObserver:self selector:@selector(keyboardDidHide) name:UIKeyboardWillHideNotification object:nil];
_keyboardIsVisible = NO;
}
return self;
}
- (void)keyboardDidShow
{
_keyboardIsVisible = YES;
}
- (void)keyboardDidHide
{
_keyboardIsVisible = NO;
}
- (BOOL)keyboardIsVisible
{
return _keyboardIsVisible;
}
转载自:http://blog.sina.com.cn/s/blog_6531b9b80101c20u.html
参考:http://www.cnblogs.com/xinus/archive/2013/01/22/ios-keybord-notification.html
其实这个解决很简单:
写一个单例来管理键盘的状态。
这个单例在初始化方法init种监听2个事件,分别是
UIKeyboardDidShowNotification(键盘弹出通知)和
UIKeyboardWillHideNotification (键盘消失通知 然后在相应的方法中设置一个属性就行了。
大致的实现如下:
-(id)init
{
self = [super init];
if (self)
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(keyboardDidShow) name:UIKeyboardDidShowNotification object:nil];
[center addObserver:self selector:@selector(keyboardDidHide) name:UIKeyboardWillHideNotification object:nil];
_keyboardIsVisible = NO;
}
return self;
}
- (void)keyboardDidShow
{
_keyboardIsVisible = YES;
}
- (void)keyboardDidHide
{
_keyboardIsVisible = NO;
}
- (BOOL)keyboardIsVisible
{
return _keyboardIsVisible;
}
转载自:http://blog.sina.com.cn/s/blog_6531b9b80101c20u.html
参考:http://www.cnblogs.com/xinus/archive/2013/01/22/ios-keybord-notification.html
相关文章推荐
- ios如何判断键盘是否已经显示
- IOS开发中如何判断程序第一次启动(根据判断结果决定是否显示新手操作引导)
- 如何在Ubuntu手机中判断键盘是否已经开启
- 关于TdxTreeList控件中如何判断点CHECK标题是否已经选中或取消自己的问题?
- 如何判断表是否已经存在
- MFC中如何判断对话框是否显示
- PB中如何控制判断大写以及小键盘指示灯是否开启并与按键协调工作
- 判断一个类是否支持某属性和方法以及如何判断IOS的版本
- 如何判断socket是否已经断开和防止外部攻击,只连接不传输数据
- 如何判断注册用户是否已经存在(membership验证)
- 【转】如何判断SQL中是否已经存在某表、存储过程、函数等
- 在linux下如何判断是否已经安装某个软件?
- 如何判断一个类是否支持某属性和方法以及如何判断IOS的版本
- 如何判断系统是否已经安装IIS服务.txt
- 检测input每次的输入是否合法遇到汉字输入就有问题,如何判断汉字是否已经输入到input内???
- 如何用DataGrid实现根据日期判断是否显示New标志
- magento -- magento中如何判断一个用户是否已经登陆
- Python 中如何判断变量是否已经定义
- 如何判断数据库中是否已经存在某个临时表?
- 多线程如何判断全部线程是否已经全部结束?