您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页iOS键盘弹出消失监听

iOS键盘弹出消失监听

来源:伴沃教育

iOS 监听键盘的弹出,收起,并且拿到键盘的高度

//监听当键盘将要出现时

[[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 *)notification

{

//获取键盘的高度

NSDictionary *userInfo = [notification userInfo];

NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

CGRect keyboardRect = [value CGRectValue];

int height = keyboardRect.size.height;

}

//当键退出

- (void)keyboardWillHide:(NSNotification *)notification

{

//获取键盘的高度

NSDictionary *userInfo = [notification userInfo];

NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

CGRect keyboardRect = [value CGRectValue];

int height = keyboardRect.size.height;

}

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

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

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