Swift - How to stop an animation?

Asked

Viewed 34 times

1

In my initial Viewcontroler I have a slide that keeps loading from the internet and alternating on the screen images at a time stipulated by me.

How can I stop the animation? I wanted to do this before going to another Viewcontroller

Animation:

func animate(images: [String], index: Int = 0) {
    print(index)
    UIView.transitionWithView(imageView, duration: 10, options: .TransitionCrossDissolve, animations: {
        if let checkedUrl = NSURL(string: self.vetString[index]) {
            self.downloadImage(checkedUrl)
        }
        }, completion: { value in
            let idx = index == images.count-1 ? 0 : index+1
            self.animate(self.vetString, index: idx)
    })
}

1 answer

0


I figured out a way. I did it this way:

@IBAction func paraAnimacao(sender: AnyObject) {
    var layer = imageView.layer.presentationLayer() as! CALayer
    var frame = layer.frame
    print(frame)
    imageView.layer.removeAllAnimations()
    imageView.frame = frame
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.