iOS开发中的键盘高度变化处理

- (void)viewWillDisappear:(BOOL)animated

{

[[NSNotificationCenterdefaultCenter] removeObserver:selfname:UIKeyboardWillShowNotificationobject:nil];

[[NSNotificationCenterdefaultCenter] removeObserver:selfname:UIKeyboardWillHideNotificationobject:nil];

}

 

- (void)viewDidLoad

{

    [superviewDidLoad];

    

    [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotificationobject:nil];

    [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotificationobject:nil];

    

 }

 

 

 

#pragma mark -

#pragma mark Responding to keyboard events

- (void)keyboardWillShow:(NSNotification *)notification {

    [self keyboardWillShowHide:notification];

 

}

- (void)keyboardWillHide:(NSNotification *)notification {

    [self keyboardWillShowHide:notification];

 

}

- (void)keyboardWillShowHide:(NSNotification *)notification

{

    CGRect keyboardRect = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

//UIViewAnimationCurve curve = [[notification.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];

double duration = [[notification.userInfoobjectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];

    

    

    CGFloat keyboardY = [self.view convertRect:keyboardRect fromView:nil].origin.y;

    

    

    NSLog(@"keyboardY :%f",keyboardY);

 

    

    [UIViewanimateWithDuration:duration

                          delay:0.0f

                        options:UIViewAnimationOptionCurveEaseInOut//[UIView animationOptionsForCurve:curve]

                     animations:^{

                         CGFloat keyboardY = [self.view convertRect:keyboardRect fromView:nil].origin.y;

                         CGFloat keyboardH = [self.view convertRect:keyboardRect fromView:nil].size.height;

                         

                         imgUpload.frame = CGRectMake(5+33, keyboardY-33, 33, 33);

                         imgURL.frameCGRectMake(5, keyboardY-33, 33, 33);

                         

                         NSLog(@"keyboardY   %f",keyboardH);

                     }

                     completion:^(BOOL finished) {

                     }];

 

}

 

posted @ 2013-06-13 10:44  StevenFu  阅读(373)  评论(0编辑  收藏  举报