3

当我旋转 iPad 时,所有动画组件(例如视图/按钮)将回到它们最初加载时的原始位置。有什么办法可以防止这种情况发生吗?

这是我单击按钮时为对象设置动画的方式,例如

- (IBAction)button1Pressed:(id)sender{

    [UIView animateWithDuration:ANIMATION_SPEED
                          delay:0.0
                        options:UIViewAnimationOptionBeginFromCurrentState
                     animations:(void (^)(void)) ^{
                         self.view.userInteractionEnabled = NO;
                         _button1.center = CGPointMake(73.01, 419.0);
                         _button2.center = CGPointMake(750.0, 419.0);
                         _button3.center = CGPointMake(850.0, 419.0);
                         _button4.center = CGPointMake(950.0, 419.0);

                         CGRect theFrame = _loginView.frame;
                         theFrame.size.width = 576.f;
                         _View1.frame = theFrame;
                         _View2.frame = CGRectMake(_button2.center.x + 44.0, _button2.center.y / 2 - 89.0, 0.0, 597.0);
                         _View3.frame = CGRectMake(_button3.center.x + 44.0, _button3.center.y / 2 - 89.0, 0.0, 597.0);
                         _4View.frame = CGRectMake(_button4.center.x + 44.0, _button4.center.y / 2 - 89.0, 0.0, 597.0);
                     }
                     completion:^(BOOL finished){
                         self.view.userInteractionEnabled = YES;
                     }];
}

我还是很新,所以所有的细节都将不胜感激:)

4

2 回答 2

0

我建议您为要设置动画的界面创建约束。然后为任何视图元素添加对这些约束的头文件的引用。

在此处输入图像描述

当您想要为视图设置动画时,您现在必须更新其约束并要求布局视图。

[UIView animateWithDuration:0.2
                         animations:^{
                             //in this case, I add 44 to my button Y position, so it will goes down 44px 
                             buttonYConstraint.constant += 44;
                             [self.view layoutIfNeeded];
                         }
]
//Now don't forget to update constraints
[self.view updateConstraints];
于 2013-11-05T13:16:35.043 回答
0

关闭位于“界面生成器文档”下的自动布局以快速方式解决了这个问题:)

于 2013-12-11T16:07:36.663 回答