您的位置:首页 > 其它

iPhone获取键盘高度,通知方式隐藏和显示键盘

2014-05-07 15:46 363 查看
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil]; 
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasHidden:) name:UIKeyboardDidHideNotification object:nil]; 

- (void) keyboardWasShown:(NSNotification *) notif{ 
    NSDictionary *info = [notif userInfo]; 
    NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey]; 
    CGSize keyboardSize = [value CGRectValue].size; 

    NSLog(@"keyBoard:%f", keyboardSize.height);  //216 
    keyboardWasShown = YES; 


- (void) keyboardWasHidden:(NSNotification *) notif{ 
    NSDictionary *info = [notif userInfo]; 
    
    NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey]; 
    CGSize keyboardSize = [value CGRectValue].size; 
   NSLog(@"keyboardWasHidden keyBoard:%f", keyboardSize.height); 
    keyboardWasShown = NO; 
    
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iphone