Objective-C-如何监测键盘的高度(iOS)
2016-09-21 13:55
260 查看
//想要监测键盘的高度,我在这里用的是通知的方法
//通知中心
NSNotificationCenter *center=[NSNotificationCenter
defaultCenter];
//当键盘将要弹起时候执行方法UIKeyboardWillShowNotification
[center addObserver:self
selector:@selector(willShow:)
name:UIKeyboardWillShowNotification
object:nil];
//键盘将要收起时执行方法UIKeyboardWillHideNotification
[center addObserver:self
selector:@selector(willHide:)
name:UIKeyboardWillHideNotification
object:nil];
//键盘出现的方法
-(void)willShow:(NSNotification *)notice{
//通知里的内容
NSDictionary *userInfo = [notice
userInfo];
NSValue *aValue = [userInfo
objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [aValue
CGRectValue];
//键盘的高度
CGFloat keyBoardHeight = keyboardRect.size.height;
//动画
[UIView
animateWithDuration:0.25
animations:^{
}completion:^(BOOL finished){
}];
}
//键盘收起的方法
-(void)willHide:(NSNotification *)notice{
//动画
[UIView
animateWithDuration:0.25
animations:^{
}completion:^(BOOL finished){
}];
}
//通知中心
NSNotificationCenter *center=[NSNotificationCenter
defaultCenter];
//当键盘将要弹起时候执行方法UIKeyboardWillShowNotification
[center addObserver:self
selector:@selector(willShow:)
name:UIKeyboardWillShowNotification
object:nil];
//键盘将要收起时执行方法UIKeyboardWillHideNotification
[center addObserver:self
selector:@selector(willHide:)
name:UIKeyboardWillHideNotification
object:nil];
//键盘出现的方法
-(void)willShow:(NSNotification *)notice{
//通知里的内容
NSDictionary *userInfo = [notice
userInfo];
NSValue *aValue = [userInfo
objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [aValue
CGRectValue];
//键盘的高度
CGFloat keyBoardHeight = keyboardRect.size.height;
//动画
[UIView
animateWithDuration:0.25
animations:^{
}completion:^(BOOL finished){
}];
}
//键盘收起的方法
-(void)willHide:(NSNotification *)notice{
//动画
[UIView
animateWithDuration:0.25
animations:^{
}completion:^(BOOL finished){
}];
}
相关文章推荐
- IOS 开发如何获取键盘高度
- iOS、Xcode监测键盘的显示和隐藏变化,并获得键盘高度,改变tableView的frame和偏移
- [iOS]如何动态获取键盘的高度
- iOS监测第三方键盘高度
- iOS如何获取系统键盘的高度
- iOS、Xcode监测键盘的显示和隐藏变化,并获得键盘高度,改变tableView的frame和偏移
- Objective-C-如何自定义键盘(iOS)
- iOS开发中如何在键盘弹出时改变View的高度
- IOS开发 如何获取搜狗输入法键盘高度
- 如何完美适应iOS中的键盘高度变化
- ios如何实现被键盘遮挡时,带有textfield的tableview自动上移
- iOS开发中的键盘高度变化处理
- 中/E文键盘切换高度监测
- IOS中如何获取string的宽度和高度
- [ios] 适应键盘高度变化
- [置顶] Objective-C ,ios,iphone开发基础:在UITextField输入完以后,隐藏键盘,
- ios 动态监听键盘输入法和高度
- ios 动态监听键盘输入法和高度
- iOS开发 关于键盘高度
- ios键盘高度