Ios 在键盘显示时设置UITextField的动画

Ios 在键盘显示时设置UITextField的动画,ios,animation,swift,Ios,Animation,Swift,我在NSNotificationCenter中注册了两名观察员,keyboardWillShow:和keyboardWillHide: 在这两种方法中,当我尝试设置包含UIExtView的UIView的动画时,它会跳到我尝试设置动画的帧,然后再设置回原始位置的动画。我在touchesbearth方法中尝试了同样的动画代码来测试它,它在那里工作得非常好,为我实际设置的新帧设置动画,而不是跳转并设置动画回到原始位置 func keyboardWillShow(notification: NSNoti

我在NSNotificationCenter中注册了两名观察员,keyboardWillShow:和keyboardWillHide:

在这两种方法中,当我尝试设置包含UIExtView的UIView的动画时,它会跳到我尝试设置动画的帧,然后再设置回原始位置的动画。我在touchesbearth方法中尝试了同样的动画代码来测试它,它在那里工作得非常好,为我实际设置的新帧设置动画,而不是跳转并设置动画回到原始位置

func keyboardWillShow(notification: NSNotification) {
    if let endFrame = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue() {
        UIView.animateWithDuration(1.0, animations: { () -> Void in
            self.footerView.center = CGPointMake(self.footerView.center.x, self.footerView.center.y - endFrame.size.height)
        })
    }
}

我被难住了。键盘通知是否以某种方式影响新动画

必须调用这两种方法来设置视图的上下动画

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
@try
{
    if (textField == (UITextField *)[self.view viewWithTag:TEXTFIELD_MOBILE_TAG])
    {
        CGRect selfframe = CGRectMake([self.view viewWithTag:VIEW_PARENT_TAG].frame.origin.x, [self.view viewWithTag:VIEW_PARENT_TAG].frame.origin.y - 80, [self.view viewWithTag:VIEW_PARENT_TAG].frame.size.width, [self.view viewWithTag:VIEW_PARENT_TAG].frame.size.height);
        [UIView animateWithDuration:0.3 animations:^{ [self.view viewWithTag:VIEW_PARENT_TAG].frame = selfframe;}];
        [textField becomeFirstResponder];
    }

}
@catch (NSException *exception)
{
    NSLog(@"Error Occured in SignUpViewController :: textViewDidBeginEditing :: %@",[exception description]);
}

}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
@try
{
    if (textField == (UITextField *)[self.view viewWithTag:TEXTFIELD_MOBILE_TAG])
    {
        CGRect selfframe = CGRectMake([self.view viewWithTag:VIEW_PARENT_TAG].frame.origin.x, [self.view viewWithTag:VIEW_PARENT_TAG].frame.origin.y + 80, [self.view viewWithTag:VIEW_PARENT_TAG].frame.size.width, [self.view viewWithTag:VIEW_PARENT_TAG].frame.size.height);
        [UIView animateWithDuration:0.3 animations:^{ [self.view viewWithTag:VIEW_PARENT_TAG].frame = selfframe;}];
        [textField resignFirstResponder];
    }
}
@catch (NSException *exception)
{
    NSLog(@"error Occured in SignUpViewController :: textViewDidEndEditing :: %@",[exception description]);
}

}

我通常在UITextViewDelegate中设置键盘上方视图的动画。-例如BOOLtextViewShouldBeginEditing:UITextView*textView。您是否以任何方式访问键盘的大小,或者仅通过某个常量设置视图的动画?我之所以尝试使用NSNotificationCenter,以便使用UIKeyboardFrameEndUserInfoKey访问键盘新框架
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
@try
{
    if (textField == (UITextField *)[self.view viewWithTag:TEXTFIELD_MOBILE_TAG])
    {
        CGRect selfframe = CGRectMake([self.view viewWithTag:VIEW_PARENT_TAG].frame.origin.x, [self.view viewWithTag:VIEW_PARENT_TAG].frame.origin.y - 80, [self.view viewWithTag:VIEW_PARENT_TAG].frame.size.width, [self.view viewWithTag:VIEW_PARENT_TAG].frame.size.height);
        [UIView animateWithDuration:0.3 animations:^{ [self.view viewWithTag:VIEW_PARENT_TAG].frame = selfframe;}];
        [textField becomeFirstResponder];
    }

}
@catch (NSException *exception)
{
    NSLog(@"Error Occured in SignUpViewController :: textViewDidBeginEditing :: %@",[exception description]);
}

}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
@try
{
    if (textField == (UITextField *)[self.view viewWithTag:TEXTFIELD_MOBILE_TAG])
    {
        CGRect selfframe = CGRectMake([self.view viewWithTag:VIEW_PARENT_TAG].frame.origin.x, [self.view viewWithTag:VIEW_PARENT_TAG].frame.origin.y + 80, [self.view viewWithTag:VIEW_PARENT_TAG].frame.size.width, [self.view viewWithTag:VIEW_PARENT_TAG].frame.size.height);
        [UIView animateWithDuration:0.3 animations:^{ [self.view viewWithTag:VIEW_PARENT_TAG].frame = selfframe;}];
        [textField resignFirstResponder];
    }
}
@catch (NSException *exception)
{
    NSLog(@"error Occured in SignUpViewController :: textViewDidEndEditing :: %@",[exception description]);
}

}