UIView.animateWithDuration暂停applicationDidEnterBackground

时间:2015-04-23 10:46:09

标签: ios swift uiviewanimation appdelegate

通常我会尝试找到自己的解决方案,但这次我不知道。 对不起,如果我有任何错误。我是swift的新手,也是堆栈溢出的新手。

我正在做一个矩形的正常动画(称为风景),它会重复,直到我说不出来。

func startAnimationReact() {
    let duration = 5.0
    let options = (UIViewAnimationOptions.Repeat |
        UIViewAnimationOptions.BeginFromCurrentState)
    UIView.animateWithDuration(duration, delay: 0.0, options: options, animations: {
            self.landscape.frame = CGRect(x: 0, y: self.heightDisplay-50, width: 50, height: 50)
            }, completion: {
            finished in
            if !finished {
            }
        }
    )
}

我已经通过Apples文档找到了,我可以暂停并恢复它:

func stopAnimation() {
    pausedTime = self.landscape.layer.convertTime(CACurrentMediaTime(), fromLayer: nil)
    self.landscape.layer.speed = 0.0
    self.landscape.layer.timeOffset = pausedTime
    }

func resumeAnimation() {
    self.landscape.layer.speed = 1.0
    self.landscape.layer.timeOffset = 0.0
    self.landscape.layer.beginTime = 0.0
    timeSincePause = self.landscape.layer.convertTime(CACurrentMediaTime(), fromLayer: nil) - pausedTime
    self.landscape.layer.beginTime = timeSincePause
}

它有效。 但是现在我想要在applicationDidEnterBackground()中调用stopAnimation,以便在我回来时将它保持在相同的位置。但它不起作用,似乎该应用程序正在自动删除动画。

有人有个主意吗?我很感激任何解决方案。

0 个答案:

没有答案
相关问题