以第一张图像

时间:2015-11-10 22:38:38

标签: arrays swift animation ios9

因此,对于加载动画,我有一个循环通过一堆图像的图像视图。问题是当它完成循环时它会返回到数组的第一个图像,即使我希望它在最后一个上完成。我尝试将它设置为完成块中的最后一个图像(我目前已注释掉该行),但它不起作用。有什么建议?谢谢!

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)

}


}

1 个答案:

答案 0 :(得分:0)

要更好地控制动画的特定帧,您需要实现自己的动画循环。基本上,创建一个重复计时器,在每一步从内存加载PNG,然后在视图中显示。不要使用animationImages,因为如果动画太长或帧太大,它会吞噬你的所有应用程序内存并导致系统崩溃。有关详细信息,请参阅this answer