IT虾米网

iOS监听系统键盘的出现和消失

xmjava 2018年06月24日 手机开发 1183 0
//注册键盘出现的通知 
 
    [[NSNotificationCenter defaultCenter] addObserver:self 
 
                                             selector:@selector(keyboardWasShown:) 
 
                                                 name:UIKeyboardWillShowNotification object:nil]; 
 
    //注册键盘消失的通知 
 
    [[NSNotificationCenter defaultCenter] addObserver:self 
 
                                             selector:@selector(keyboardWillBeHidden:) 
 
                                                 name:UIKeyboardWillHideNotification object:nil]; 
 
- (void)keyboardWasShown:(NSNotification*)aNotification 
 
{ 
 
    //键盘高度 
 
    CGRect keyBoardFrame = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; 
 
} 
 
 
-(void)keyboardWillBeHidden:(NSNotification*)aNotification 
 
{ 
 
 
}

评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!