【问题标题】:iOS prevent rotations until after animation completesiOS 阻止旋转直到动画完成
【发布时间】:2014-01-29 21:31:46
【问题描述】:

我正在创建一个 iOS 应用,在一种方法中,我有一个 for 循环,它会执行一系列持续约 2 秒的动画。

我的问题是,如果用户在动画仍在播放时旋转设备,它会弄乱新方向的格式(如果旋转发生之后,一切都会按原样进行动画完成)。

所以我想知道是否有办法延迟轮换

【问题讨论】:

  • 你在使用UIView动画块吗?
  • 是的,我正在使用动画块

标签: 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;
        }
    }];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多