当前位置: 首页 > 工具软件 > UIKeyboard > 使用案例 >

UIKeyBoard高度的监控

燕砚文
2023-12-01

监控KeyBoard


    [[NSNotificationCenter defaultCenteraddObserver:self selector:@selector(keyBoardWillShow:)name:UIKeyboardWillShowNotification object:nil];

    [[NSNotificationCenter defaultCenteraddObserver:self selector:@selector(keyBoardWillHidden:)name:UIKeyboardWillHideNotification object:nil];


显示的实现

- (void) keyBoardWillShow:(NSNotification*) notification

{

    

    NSDictionary *userInfo = [notification userInfo];

    

    // Get the origin of the keyboard when it's displayed.

    NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

    

    // Get the top of the keyboard as the y coordinate of its origin in self's view's coordinate system. The bottom of the text view's frame should align with the top of the keyboard's final position.

    CGRect keyboardEndFrame = [aValue CGRectValue];

    CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil];


    CGFloat keyboardHeight = keyboardFrame.size.height;    

}

 类似资料: