当我旋转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;
}];
}
我还是很新,所以所有细节都将受到赞赏:)
答案 0 :(得分: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];
答案 1 :(得分:0)
关闭位于“界面构建器文档”下的自动布局,以快速方式修复此问题:)