获取系统键盘的高度

来源:互联网 发布:海上钢琴师 知乎 编辑:程序博客网 时间:2024/05/27 14:13

- (void)viewWillAppear:(BOOL)animated

{

    [superviewWillAppear:animated];

    [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotificationobject:nil];

    [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillHide:)name:UIKeyboardWillHideNotificationobject:nil];

    

}

- (void)viewDidDisappear:(BOOL)animated

{

    [superviewWillAppear:animated];

    [[NSNotificationCenterdefaultCenter]removeObserver:selfname:UIKeyboardWillShowNotificationobject:nil];

    [[NSNotificationCenterdefaultCenter]removeObserver:selfname:UIKeyboardWillHideNotificationobject:nil];

}

#pragma mark - 获取键盘的高度

- (void)keyboardWillShow:(NSNotification *)note

{

    //获取键盘的高度

    NSDictionary *userInfo = [noteuserInfo];

//    NSLog(@"keyboard:%@",userInfo);

    NSValue *aValue = [userInfoobjectForKey:UIKeyboardFrameEndUserInfoKey];

    CGRect keyboardRect = [aValueCGRectValue];

    keyboardHeight = keyboardRect.size.height;

}

- (void)keyboardWillHide:(NSNotification *)note

{

}

0 0
原创粉丝点击