美文网首页
监听 键盘

监听 键盘

作者: 奕珃 | 来源:发表于2017-08-17 15:14 被阅读0次

    //注册键盘出现的通知

    [[NSNotificationCenter defaultCenter]addObserver:self

    selector:@selector(keyboardWasShown:)

    name:UIKeyboardWillShowNotification object:nil];

    //注册键盘消失的通知

    [[NSNotificationCenterdefaultCenter]addObserver:self

    selector:@selector(keyboardWillBeHidden:)

    name:UIKeyboardWillHideNotification object:nil];

    //键盘出来时的操作

    - (void)keyboardWasShown:(NSNotification*)aNotification

    {

    //键盘高度

    CGRect keyBoardFrame = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];

    }

    //键盘消失时的操作

    -(void)keyboardWillBeHidden:(NSNotification*)aNotification

    {

    }

    记得最后要删除监听 

    - (void)dealloc {

    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];

    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];

    }

    相关文章

      网友评论

          本文标题:监听 键盘

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