简体   繁体   中英

Animation doesn't start after reopening the app?

Objective

I need my app to scale a UIImage .

Code

To do so, I use this method:

func animateStuff() {

    println("Animate stuff called!")

    let optionsAnimateStuff = UIViewAnimationOptions.Repeat | UIViewAnimationOptions.Autoreverse | UIViewAnimationOptions.AllowUserInteraction
    let value : CGFloat = 1.045

               UIView.animateWithDuration(0.9, delay: 0.0, options:
                optionsAnimateStuff, animations: {

                    println("Let's scale this image!")

                self.image.transform = CGAffineTransformMakeScale(value, value)

            }, completion: { finished in })
}

When I close the app and open it again the method gets called again (due to the code inside applicationDidBecomeActive but the UIImage does not animate anymore.

Question

Why doesn't the object animate?

The problem might be that the image still has the previous transform applied. You likely want to return it to its original when the animation completes (when the view goes away).

Try using this code in your completion :

{ finished in
    self.image.transform = CGAffineTransformIdentity
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM