当前位置:编程学习 > wap >>

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

print?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;  
}  
 
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 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,