So I want to make an animated background in xcode6 using swift. In Photoshop Ive made 10 gradient circle images. The first image is barley visible (Transparent) and the Last image is 100% visible. So in xcode, I want to make a frame by frame animation that will animate the images from barley visible to 100% visible. But im not sure how to code this with swift. Any help would be great!
@IBOutlet weak var animatedPicture: UIImageView!
animatedPicture.animationImages = [NSArray arrayWithObjects:
[UIImage imagedNamed @"Fadein1.png"],
[UIImage imageNamed @"Fadein2.png"],
I’m thinking something like this. But in swift, Not Objective-C.
2
Answers
If all you want to do is change the alpha, then just use the 100% visible image and
UIView.animateWithDuration()
If more is going on with the images than just changing the alpha, then check out
UIImageView.animationImages()
and its related methods.Images.xcassets
named like this:Add a
UIImageView
to yourViewController
throughStoryBoard
Create an
IBOutlet
to theUIImageView
Import these in your
ViewController
Create an empty
Array
for the imagesLoop through the
Array
ofUIImage
s(“999” should replaced with the amount of frames you are using. Also, your first frame must end with all zeros i.e. Frame000)
Set a duration and start the animation! (It will loop forever unless you add
imageView.animationRepeatCount
)Check this link if you are still having trouble