关闭

IOS 开发如何获取键盘高度

标签: 键盘
256人阅读 评论(0) 收藏 举报
分类:
 - (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 *)aNotification

{

    //获取键盘的高度

    NSDictionary *userInfo = [aNotification userInfo];

    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

    CGRect keyboardRect = [aValue CGRectValue];

    int height = keyboardRect.size.height;

}


//当键退出时调用

- (void)keyboardWillHide:(NSNotification *)aNotification

{

    

}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:10866次
    • 积分:227
    • 等级:
    • 排名:千里之外
    • 原创:9篇
    • 转载:19篇
    • 译文:0篇
    • 评论:0条