iOS成长之路-获取系统键盘的高度

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
    //UIKeyboardWillShowNotification键盘出现
    [defaultCenter addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

    //UIKeyboardWillHideNotification 键盘隐藏
    [defaultCenter addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

- (void)keyboardWillShow:(NSNotification *)aNotification
{
    //获取键盘的高度
	NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    int height = keyboardRect.size.width;
}

你可能感兴趣的:(iOS成长之路-获取系统键盘的高度)