美文网首页
基础迁移-键盘弹起 收回

基础迁移-键盘弹起 收回

作者: 忆往昔Code | 来源:发表于2018-12-20 15:09 被阅读0次

//监听当键盘将要出现时
[[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;

}

相关文章

网友评论

      本文标题:基础迁移-键盘弹起 收回

      本文链接:https://www.haomeiwen.com/subject/rcvykqtx.html