您好,欢迎来到知库网。
搜索
您的当前位置:首页iOS 获取键盘高度

iOS 获取键盘高度

来源:知库网

- (void) registerForKeyboardNotifications{

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];

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

}

- (void) keyboardWasShown:(NSNotification *) notif{

NSDictionary *info = [notif userInfo];

NSValue *value = [info objectForKey:UIKeyboardBoundsUserInfoKey];

CGSize keyboardSize = [value CGRectValue].size;

CGRect scrollViewFrame= [scrollView frame];

scrollViewFrame.size.height -= keyboardSize.height;

scrollView.frame = scrollViewFrame;

[scrollView scrollRectToVisible:inputElementFrame animated:YES];

keyboardWasShown = YES;

}

- (void) keyboardWasHidden:(NSNotification *) notif{

NSDictionary *info = [notif userInfo];

NSValue *value = [info objectForKey:UIKeyboardBoundsUserInfoKey];

CGSize keyboardSize = [value CGRectValue].size;

CGRect scrollViewFrame= [scrollView frame];

scrollViewFrame.size.height += keyboardSize.height;

scrollView.frame = scrollViewFrame;

keyboardWasShown = NO;

}

Copyright © 2019- zicool.com 版权所有 湘ICP备2023022495号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务