监听键盘高度oc---swfit
2016-11-29 16:26
183 查看
oc:- (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 *)noti{ NSDictionary *userInfo = [noti userInfo]; NSValue *v = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; CGRect keyboardRect = [v CGRectValue]; int height = keyboardRect.size.height;}- (void)keyboardWillHide:(NSNotification *)aNotification{}swift:
override func 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) } func keyboardWillShow(noti: NSNotification) { let userInfo = (noti.userInfo)! as NSDictionary let v = (userInfo.objectForKey(UIKeyboardFrameEndUserInfoKey)) as! NSValue let keyboardRect = v.CGRectValue() let height = keyboardRect.size.height } func keyboardWillHide(noti: NSNotification) { }
- (void)keyboardWillShow:(NSNotification *)noti{ NSDictionary *userInfo = [noti userInfo]; NSValue *v = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; CGRect keyboardRect = [v CGRectValue]; int height = keyboardRect.size.height;}- (void)keyboardWillHide:(NSNotification *)aNotification{}swift:
override func 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) } func keyboardWillShow(noti: NSNotification) { let userInfo = (noti.userInfo)! as NSDictionary let v = (userInfo.objectForKey(UIKeyboardFrameEndUserInfoKey)) as! NSValue let keyboardRect = v.CGRectValue() let height = keyboardRect.size.height } func keyboardWillHide(noti: NSNotification) { }
相关文章推荐
- iOS-OC-监听键盘的高度 隐藏和出现
- 获得软键盘高度 监听软键盘
- iOS开发之监听键盘高度的变化
- iOS开发之监听键盘高度的变化
- 在android中键盘弹出和收起会改变window的高度,因此监听window的resize
- Android监听键盘是否弹出,以及获取软键盘的高度
- 简单的监听键盘出现和消失的方法以及得到键盘高度
- 监听键盘高度
- iOS获取键盘弹出高度,监听键盘弹出退出
- 用通知监听键盘的出现与消失,与获取键盘高度
- iOS开发之监听键盘高度的变化
- iOS 监听键盘高度,监听键盘出现 收回事件
- ios 动态监听键盘输入法和高度
- 软键盘的弹出隐藏监听及软键盘高度
- iOS 评论界面 监听键盘高度 动态改变输入框位置
- iOS - 通知监听键盘高度
- iOS技巧——即时监听键盘高度
- 动态监听键盘高度调整文本输入框
- ios 动态监听键盘输入法和高度
- ios键盘高度监听