We want an image show
and hide many times, looming like fen-fire.
Declare an image above
viewDidLoad.
let im = UIImage(named: "image")
Add these lines inside
viewDidLoad.
UIGraphicsBeginImageContextWithOptions(im!.size, false, 0)
let empty = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
var te=[UIImage](count: 5, repeatedValue: im!)
te.append(im!)
te.append(empty)
te.append(im!)
te.append(empty)
te.append(im!)
let iv = UIImageView(image:empty)
iv.frame.origin = CGPointMake(100,50)
self.view.addSubview(iv)
iv.animationImages = te
iv.animationDuration = 2
iv.animationRepeatCount = 100
iv.startAnimating()
Run to see result, this
effect can attract user attention when we show a warning. To change repeat
times, edit animationRepeatCount.
No comments:
Post a Comment