Niko
Niko

Reputation: 1004

Swift - finding the size of a UIImageview after an animation is interrupted/cancelled?

I'm creating a game where the size of my UIImage is changing and the user has to press the screen at the right time to stop the animation. The end size is then compared to a fixed constant to give the user points based on how close they were. Is there a way to use the .removeAllAnimations() method and get the size at that time? I tried using view.bounds, view.frame, view.layer.frame, and view.layer.bounds and they're all wrong. Is there another method altogether that I should be using?

Upvotes: 0

Views: 51

Answers (1)

Adrian Sluyters
Adrian Sluyters

Reputation: 2241

both UIView and UIViewController (as well as NSView and NSViewController) act as CAAnimationDelegate which has the methods:

override func animationDidStop(anim: CAAnimation, finished flag: Bool)        
override func animationDidStart(anim: CAAnimation)

So set the delegate of your animation to whichever view, controller and use those methods to handle the stop, start events.

e.g.

    let anim = CAAnimation()
    ... set animation up here
    anim.delegate = self

Upvotes: 1

Related Questions