注册键盘通知,动态读取键盘的高度

阅读更多

动态读取键盘的高度

 

 

 

- (void) registerForKeyboardNotifications

{

    [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotificationobject:nil];

    

    [[NSNotificationCenterdefaultCenteraddObserver:selfselector:@selector(keyboardWasHidden:) name:UIKeyboardDidHideNotificationobject:nil];

    

    [[NSNotificationCenterdefaultCenteraddObserver:selfselector:@selector(keyChangeFrame:) name:UIKeyboardWillChangeFrameNotificationobject:nil];

}

 

- (void) keyboardWasShown:(NSNotification *) notif

{

    NSDictionary *info = [notif userInfo];

    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];

    CGSize keyboardSize = [value CGRectValue].size;

    

    SJBLog(@"keyBoard:%f", keyboardSize.height);  //216

    self.myLabel.frame = CGRectMake(0, APPBOUND.size.height-keyboardSize.height-44-35, APPBOUND.size.width, 35);

    ///keyboardWasShown = YES;

}

- (void) keyboardWasHidden:(NSNotification *) notif

{

    NSDictionary *info = [notif userInfo];

    

    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];

    CGSize keyboardSize = [value CGRectValue].size;

    SJBLog(@"keyboardWasHidden keyBoard:%f", keyboardSize.height);

    // keyboardWasShown = NO;

    

}

 

- (void) keyChangeFrame:(NSNotification *) notif

{

    NSDictionary *info = [notif userInfo];

    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];

    CGSize keyboardSize = [value CGRectValue].size;

    

    SJBLog(@"keyBoard:%f,,,info==%@", keyboardSize.height,info);  //216

    self.myLabel.frame = CGRectMake(0, APPBOUND.size.height-keyboardSize.height-44-35, APPBOUND.size.width, 35);

    ///keyboardWasShown = YES;

 

}

你可能感兴趣的:(通知,键盘toolbar,键盘上放UILabel)