Objective-C-如何监测键盘的高度(iOS)

//想要监测键盘的高度,我在这里用的是通知的方法

//通知中心

    NSNotificationCenter *center=[NSNotificationCenter defaultCenter];

    //当键盘将要弹起时候执行方法UIKeyboardWillShowNotification

    [center addObserver:self selector:@selector(willShow:) name:UIKeyboardWillShowNotification object:nil];

    //键盘将要收起时执行方法UIKeyboardWillHideNotification

    [center addObserver:self selector:@selector(willHide:) name:UIKeyboardWillHideNotification object:nil];


//键盘出现的方法

-(void)willShow:(NSNotification *)notice{

    

    //通知里的内容

    NSDictionary *userInfo = [notice userInfo];

    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

    CGRect keyboardRect = [aValue CGRectValue];

    //键盘的高度

    CGFloat keyBoardHeight = keyboardRect.size.height;

    

    //动画

    [UIView animateWithDuration:0.25 animations:^{

        

    }completion:^(BOOL finished){

    }];

}

//键盘收起的方法

-(void)willHide:(NSNotification *)notice{

    

    //动画

    [UIView animateWithDuration:0.25 animations:^{


    }completion:^(BOOL finished){

        

    }];

}



你可能感兴趣的:(iOS,iOS开发)