监听键盘通知

//监听键盘状态 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil]; 
    //监听输入法状态 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeInputMode:) name:UITextInputCurrentInputModeDidChangeNotification object:nil]; 

 
#pragma mark Notification 
//keyBoard已经展示出来 
- (void)keyboardDidShow:(NSNotification *)notification 

    NSValue* aValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]; 
    CGRect keyboardRect = [aValue CGRectValue]; 
    CGRect keyboardFrame = [self.view convertRect:keyboardRect fromView:[[UIapplication sharedApplication] keyWindow]]; 
    CGFloat keyboardHeight = keyboardFrame.size.height; 
    NSLog(@"##keboardHeight=%.2f",keyboardHeight); 

 
//输入法发生切换 
-(void)changeInputMode:(NSNotification *)notification{ 
    NSString *inputMethod = [[UITextInputMode currentInputMode] primaryLanguage]; 
    NSLog(@"inputMethod=%@",inputMethod); 

posted @ 2015-12-28 08:36  zs十二  阅读(166)  评论(0)    收藏  举报