【问题标题】:iOS prevent rotations until after animation completesiOS 阻止旋转直到动画完成
【发布时间】:2014-01-29 21:31:46
【问题描述】:
我正在创建一个 iOS 应用,在一种方法中,我有一个 for 循环,它会执行一系列持续约 2 秒的动画。
我的问题是,如果用户在动画仍在播放时旋转设备,它会弄乱新方向的格式(如果旋转发生之后,一切都会按原样进行动画完成)。
所以我想知道是否有办法延迟轮换
【问题讨论】:
标签:
ios
objective-c
animation
locking
screen-rotation
【解决方案1】:
您可以拥有一个 BOOL 实例变量,您可以根据动画是否完整来更新它。然后覆盖shouldAutorotate 方法并返回BOOL。可能看起来像这样:
@implementation YourViewController {
BOOL _shouldAutoRotate;
}
-(BOOL)shouldAutorotate {
[super shouldAutorotate];
return _shouldAutoRotate;
}
-(void)yourAnimationMethod {
_shouldAutoRotate = NO;
[UIView animateWithDuration:2.0f animations:^{
//your animations
} completion:^(BOOL finished) {
if(finished) {
_shouldAutoRotate = YES;
}
}];
}