Swift - How to automatically change the Imageview image

1

I have some images and an ImageView according to the photos

I would like to be able to toggle the imageView image, switching from one to another every 5 seconds automatically.

How could I do this?

    
asked by anonymous 19.04.2016 / 19:33

2 answers

1

You can use transitionWithView:

let toImage = UIImage(named:"myname.png")
UIView.transitionWithView(self.imageView,
                          duration:5,
                          options: UIViewAnimationOptions.TransitionCrossDissolve,
                          animations: { self.imageView.image = toImage },
                          completion: nil)

Example: link

You can also use these options: link

    
19.04.2016 / 19:50
1

Just put the logic to change for each image.

NSTimer(timeInterval: 0.5, target: self, selector: "TrocarImagem", userInfo: nil, repeats: true)

func TrocarImagem() {
    let imagem = UIImage(named:"imagem01.jpg")
}
    
28.04.2016 / 22:40