Ios UITextField丢失firstResponder恢复帧动画/修改

Ios UITextField丢失firstResponder恢复帧动画/修改,ios,ios6,nsanimation,Ios,Ios6,Nsanimation,我使用以下代码修改框架大小以适应键盘的显示/消失: - (void)moveCodeViewForKeyboard:(NSNotification*)aNotification up:(BOOL)up { NSDictionary* userInfo = [aNotification userInfo]; NSTimeInterval animationDuration; UIViewAnimationCurve animationCurve; CGRect ke

我使用以下代码修改框架大小以适应键盘的显示/消失:

- (void)moveCodeViewForKeyboard:(NSNotification*)aNotification up:(BOOL)up {
    NSDictionary* userInfo = [aNotification userInfo];
    NSTimeInterval animationDuration;
    UIViewAnimationCurve animationCurve;
    CGRect keyboardEndFrame;

    [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
    [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
    [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:animationDuration];
    [UIView setAnimationCurve:animationCurve];

    CGRect newFrame = codeView.frame;
    CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil];
    keyboardFrame.size.height += keyboardToolbar.frame.size.height;
    keyboardFrame.size.height += 10;
    newFrame.size.height -= keyboardFrame.size.height * (up?1:-1);
    codeView.frame = newFrame;

    [UIView commitAnimations];
}
对于其他一些在显示/隐藏键盘时设置动画的子视图,重复此代码

点击UITextField可使所有动画正确显示。但如果我随后立即点击一个UITextView,那么之前设置动画的所有元素(UIToolbar、UITextView、UIWebView)都将恢复为其原始帧(位置和大小),并且不再设置动画。如果在UITextField是第一响应者时关闭键盘,元素将返回到原始帧,但将再次设置动画

很奇怪

只是因为我想人们会问:

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    NSLog(@"textFieldDidEndEditing");
}

提前谢谢

您的项目是否设置为使用
自动布局
?如果是,则在使用Interface Builder时会自动为您创建约束,并且仅更改构件的框架是不够的,您需要调整这些构件上的约束。通常,您可以通过将约束链接到
IBOutlet
属性并修改约束上的
常量
属性来实现这一点。

更多地使用约束后,它看起来与动画关系不大,而与修改UIView(或其子类)帧值(大小或位置)有关。父视图上必须有一些不允许持久性的设置。。。可能地