Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart animation when returning to foreground

I'm having an issue restarting an animation when the app returns to the foreground. I checked this solution, but it's not working for me.

In my App Delegate, I'm cancelling the animation when the app resigns

func applicationWillResignActive(application: UIApplication) {
    let rootVC = window?.rootViewController as! ViewController
    rootVC.boardImage.layer.removeAllAnimations()
}

And I'm posting a notification to the View Controller when the app enters the foreground

func applicationWillEnterForeground(application: UIApplication) {
    NSNotificationCenter.defaultCenter().postNotificationName("didEnterForeground", object: nil)
}

The View Controller has an observer that calls the method, but the animation isn't restarting.

Called Method:

func playAnimation(notification: AnyObject) {
    gameLogic.boardFlash(boardImage)
}

the boardFlash animation:

func boardFlash(board: UIImageView) {
    let options:UIViewAnimationOptions = [.Autoreverse, .Repeat]

    UIView.animateWithDuration(0.3, delay: 1.0, options: [options], animations: {
        board.alpha = 0.0
        }, completion: nil)
}

I checked that everything is getting called, but the animation isn't running. Any help will be greatly appreciated. Thanks!

like image 710
D. Greg Avatar asked Oct 26 '25 10:10

D. Greg


1 Answers

I solved it thanks to @BlakeLockley comment.

I set the board Image View alpha to 1.0 in the observer method call.

func playAnimation(notification: AnyObject) {
    boardImage.alpha = 1.0
    gameLogic.boardFlash(boardImage)
}

Now it works fine. Interesting solution though.

like image 107
D. Greg Avatar answered Oct 29 '25 00:10

D. Greg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!