视图随键盘的弹出整体上移UIKeyboardWillChangeFrameNotification


   [[NSNotificationCenterdefaultCenter]addObserver:self

  selector:@selector(KeyboardWillChange:)

  name:UIKeyboardWillChangeFrameNotification

  object:nil];



- (void)KeyboardWillChange:(NSNotification *)notification

{    

    NSDictionary *dict = notification.userInfo;

    CGRect KeyboardFrame = [dict[UIKeyboardFrameEndUserInfoKey]CGRectValue];

    CGFloat KeyboardY = KeyboardFrame.origin.y;

    //获取动画时间

    CGFloat duration = [dict[UIKeyboardAnimationDurationUserInfoKey]doubleValue];

    CGFloat transY = KeyboardY - self.view.frame.size.height;

    //动画

    [UIView animateWithDuration:duration animations:^{

        self.view.transform =CGAffineTransformMakeTranslation(0, transY);

    }];


}

你可能感兴趣的:(ios开发)