iOS获取键盘的高度(在键盘出现,改变和消失时通知改变)
2015-05-27 11:45
423 查看
- (void)viewDidLoad
{
[super viewDidLoad];
//增加监听,当键盘出现或改变时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
//增加监听,当键退出时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
//当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)aNotification
{
//获取键盘的高度
NSDictionary *userInfo = [aNotification userInfo];
NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [aValue CGRectValue];
float height = keyboardRect.size.height;
}
//当键退出时调用
- (void)keyboardWillHide:(NSNotification *)aNotification
{
}
{
[super viewDidLoad];
//增加监听,当键盘出现或改变时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
//增加监听,当键退出时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
//当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)aNotification
{
//获取键盘的高度
NSDictionary *userInfo = [aNotification userInfo];
NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [aValue CGRectValue];
float height = keyboardRect.size.height;
}
//当键退出时调用
- (void)keyboardWillHide:(NSNotification *)aNotification
{
}
相关文章推荐
- 用通知监听键盘的出现与消失,与获取键盘高度
- iOS之 利用通知(NSNotificationCenter)获取键盘的高度,以及显示和隐藏键盘时修改界面的注意事项
- iOS 键盘显示或消失的监听,获取键盘高度
- iOS键盘中英文切换键盘高度获取通知方法
- view的frame高度根据键盘出现、消失改变
- iOS键盘中英文切换键盘高度获取通知方法
- ios 键盘高度改变通知
- 监控键盘出现和消失,获取键盘高度
- iOS动态获取键盘高度方法
- ios --- 动态获取键盘高度
- 文本框随键盘动态改变位置(获取键盘弹起高度)
- ios判读键盘是否出现和消失
- iPhone获取键盘高度,通知方式隐藏和显示键盘
- iOS获取键盘高度
- iOS 获取键盘高度
- iOS获取键盘的高度
- iOS 获取软键盘高度
- 键盘弹起与隐藏时高度的获取及动画 适配所有iOS系统
- ios开发 监听键盘frame变化事件获取键盘高度( ios8&ios7 横竖屏旋转时需要注意的问题)
- iOS -- textfield输入时键盘升起,改变view高度