gpt4 book ai didi

ios - 旋转 iPad 会将 View 的动画重置为开始

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:41:07 26 4
gpt4 key购买 nike

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

下面是我如何在单击按钮时为对象设置动画,例如

- (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;
}];
}

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

最佳答案

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

enter image description here

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

[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];

关于ios - 旋转 iPad 会将 View 的动画重置为开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19785798/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com