动态读取键盘的高度
- (void) registerForKeyboardNotifications
{
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotificationobject:nil];
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWasHidden:) name:UIKeyboardDidHideNotificationobject:nil];
[[NSNotificationCenterdefaultCenter] addObserver: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;
}