iOS——获取键盘高度,
2016-10-17 18:14
190 查看
- (void)viewDidLoad
{
[super viewDidLoad];
//使用NSNotificationCenter 键盘出现时
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardWillShowNotification object:nil];
//使用NSNotificationCenter 键盘隐藏时
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
[self reloadBusLine];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
{
[super viewDidLoad];
//使用NSNotificationCenter 键盘出现时
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardWillShowNotification object:nil];
//使用NSNotificationCenter 键盘隐藏时
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
[self reloadBusLine];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)keyboardWillShow:(NSNotification *)notification { NSDictionary *userInfo = [notification userInfo]; NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; CGRect keyboardRect = [aValue CGRectValue]; keyboardRect = [self.view convertRect:keyboardRect fromView:nil]; CGFloat keyboardTop = keyboardRect.origin.y; CGRect newTextViewFrame = self.view.bounds; newTextViewFrame.size.height = keyboardTop - self.view.bounds.origin.y; NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]; NSTimeInterval animationDuration; [animationDurationValue getValue:&animationDuration]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:animationDuration]; textView.frame = newTextViewFrame; [UIView commitAnimations]; } - (void)keyboardWillHide:(NSNotification *)notification { NSDictionary* userInfo = [notification userInfo]; NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]; NSTimeInterval animationDuration; [animationDurationValue getValue:&animationDuration]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:animationDuration]; textView.frame = self.view.bounds; [UIView commitAnimations]; }
相关文章推荐
- iOS 获取软键盘高度
- iOS键盘中英文切换键盘高度获取通知方法
- iOS 键盘显示或消失的监听,获取键盘高度
- ios开发 动态获取中英文键盘高度
- IOS 开发如何获取键盘高度
- iOS获取键盘的高度
- 获取iOS设备键盘高度
- iOS获取键盘的高度(在键盘出现,改变和消失时通知改变)
- iOS获取键盘的高度
- [iOS]如何动态获取键盘的高度
- iOS获取键盘的高度
- ios开发 监听键盘frame变化事件获取键盘高度( ios8&ios7 横竖屏旋转时需要注意的问题)
- ios --- 动态获取键盘高度
- ios --- 动态获取键盘高度
- ios --- 动态获取键盘高度
- ios 获取键盘高度
- 键盘弹起与隐藏时高度的获取及动画 适配所有iOS系统
- iOS成长之路-获取系统键盘的高度
- IOS 获取键盘的高度
- ios --- 动态获取键盘高度