1

So for a load animation I have an image view looping through a bunch of images. The thing is that when it's done looping through it returns to the first image of the array even though I want it to finish on the last one. I try to set it to the last image in the completion block (I currently commented out the line) but it doesn't work. Any suggestions? Thank you!

import UIKit

class ViewController: UIViewController {

var logoImageView = UIImageView()
var labelImageView = UIImageView()

override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationController?.navigationBarHidden = true

    self.view.backgroundColor = UIColor(red: (253/255), green: (78/255), blue: (23/255), alpha: 1)

    //sets up logo

    logoImageView = UIImageView(frame: CGRectMake(self.view.frame.size.width / 2 - 65, self.view.frame.size.height / 2 - 165, 0, 0))
    logoImageView.image = UIImage(named: "00")
    logoImageView.backgroundColor = UIColor.clearColor()
    self.view.addSubview(logoImageView)

    //sets up ilmatic text label

    labelImageView = UIImageView(frame: CGRectMake(self.view.frame.size.width / 2 - 70, self.view.frame.size.height / 2 - 7, 140, 14))
    labelImageView.image = UIImage(named: "00_word_mark")
    labelImageView.backgroundColor = UIColor.clearColor()
    labelImageView.alpha = 0
    self.view.addSubview(labelImageView)

    //get bigger animation

    self.getBigger()
}

func getBigger(){

    UIView.animateWithDuration(2, animations: { () -> Void in

        self.logoImageView.frame = CGRectMake(self.view.frame.size.width / 2 - 65, self.view.frame.size.height / 2 - 165, 130, 130)

        }) { (completion) -> Void in

            self.performSelector("animate", withObject: self, afterDelay: 0.5)
    }

}

func animate() {

    UIView.animateWithDuration(2, animations: { () -> Void in

        let animationImages:[UIImage] = [UIImage(named: "00")!, UIImage(named: "02")!, UIImage(named: "03")!, UIImage(named: "04")!, UIImage(named: "05")!, UIImage(named: "06")!, UIImage(named: "07")!, UIImage(named: "08")!, UIImage(named: "09")!, UIImage(named: "10")!, UIImage(named: "11")!, UIImage(named: "12")!, UIImage(named: "13")!, UIImage(named: "14")!, UIImage(named: "15")!, UIImage(named: "16")!, UIImage(named: "17")!, UIImage(named: "18")!, UIImage(named: "19")!, UIImage(named: "20")!, UIImage(named: "21")!, UIImage(named: "22")!, UIImage(named: "23")!, UIImage(named: "24")!, UIImage(named: "25")!, UIImage(named: "26")!]

        self.logoImageView.animationImages = animationImages
        self.logoImageView.animationRepeatCount = 1
        self.logoImageView.animationDuration = 2
        self.logoImageView.startAnimating()

        }) { (completion) -> Void in

            UIView.animateWithDuration(4, animations: { () -> Void in

//                    self.logoImageView.image = UIImage(named: "26")

            ^^^THE ABOVE LINE DOESN T SET THE IMAGE BACK FOR SOME REASON


                self.labelImageView.alpha = 0
                self.labelImageView.alpha = 1

                }, completion: { (completion) -> Void in

                    self.performSelector("pushToCreateVC", withObject: self, afterDelay: 2)
            })

    }

}

func pushToCreateVC() {

    let createVC = CreateAccountViewController()
    self.navigationController?.pushViewController(createVC, animated: true)

}


}
Echizzle
  • 3,359
  • 5
  • 17
  • 28

1 Answers1

0

To get more control over specific frames of the animation, you will need to implement your own animation loop. Basically, create a repeating timer, load a PNG from memory on each step, then display that in the view. Do not use animationImages ever, since it will gobble up all your app memory and crash your system if the animation is too long or the frames are too big. See this answer for more info.

Community
  • 1
  • 1
MoDJ
  • 4,309
  • 2
  • 30
  • 65