获取键盘高度

来源:互联网 发布:怎么研发软件 编辑:程序博客网 时间:2024/05/16 12:40
- (void)viewDidLoad
{
    [
super viewDidLoad];
    
// Do any additional setup after loading the view.
    
self.titleTextField.delegate = self;
    
self.contextTextView.delegate = self;
    
    
//增加监听,当键盘出现或改变时收出消息
    [[
NSNotificationCenter defaultCenteraddObserver:self
                                             
selector:@selector(keyboardWillShow:)
                                                 
name:UIKeyboardWillShowNotification
                                               
object:nil];
    
    
//增加监听,当键退出时收出消息
    [[
NSNotificationCenter defaultCenteraddObserver: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.height;
}

//当键退出时调用
- (
void)keyboardWillHide:(NSNotification *)aNotification
{
    
}
0 0
原创粉丝点击