normally i try to find find on my own a solution, but this time i don't know. I'm sorry, if i do any mistakes. I'm new to swift and also new to stack overflow.
I'm doing a normal animation of a rectangle (called landscape), which repeats itself, until i say otherwise.
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 {
}
}
)
}
I already found thru Apples Documentation, that i can pause and resume it with:
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
}
And it works. But now i want, to call the stopAnimation in applicationDidEnterBackground(), to keep it at the same position, when i come back. But it's not working, it rather seems that the app is automatically removing the animation.
Anyone got an idea? I would appreciate any solution.