现在的位置: 首页 > 综合 > 正文

UIKeyBoard高度的监控

2017年12月08日 ⁄ 综合 ⁄ 共 855字 ⁄ 字号 评论关闭

监控KeyBoard


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

    [[NSNotificationCenter
defaultCenter] addObserver: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;    

}

抱歉!评论已关闭.