skip to Main Content

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


  1. 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.

    Login or Signup to reply.
    1. Add your images to Images.xcassets named like this:

    enter image description here

    1. Add a UIImageView to your ViewController through StoryBoard

    2. Create an IBOutlet to the UIImageView

    3. Import these in your ViewController

      import UIKit
      import Foundation
      
    4. Create an empty Array for the images

      imageView.animationImages = [UIImage]()
      
    5. Loop through the Array of UIImages
      (“999” should replaced with the amount of frames you are using. Also, your first frame must end with all zeros i.e. Frame000)

      for var index = 0; index < 999; index++ {
          var frameName = String(format: "Frame%03d", index) // Frame%03d means AssetName/AmountOfZeros/Increment
          imageView.animationImages?.append(UIImage(named: frameName)!)
      }
      
    6. Set a duration and start the animation! (It will loop forever unless you add imageView.animationRepeatCount)

      imageView.animationDuration = 2 // Seconds
      imageView.startAnimating()
      

    Check this link if you are still having trouble

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search