0

我想为ImageView具有多个视图控制器的项目构建动画图像。我看过的所有教程都添加了一个动画视图来拥有一个ViewController. 我对编码还很陌生,只是在构建一个演示。

我已经测试了将下面的代码应用于ViewController.swift单个视图控制器项目并且它可以工作,但是对于一个以上的 VC,它会失败。我已经在VC.swift下面发布了代码:

单视图控制器的工作代码:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var penjulumLogo: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        penjulumLogo.animationImages = [

            UIImage(named: "Storing3dot.png")!,
            UIImage(named: "Storing2dot.png")!,
            UIImage(named: "Storing1dot.png")!,
            UIImage(named: "Storing0dot.png")!,
            UIImage(named: "Encrypted3dot.png")!,
            UIImage(named: "Encrypted2dot.png")!,
            UIImage(named: "Encrypted1dot.png")!,
            UIImage(named: "Encrypted0dot.png")!,
            UIImage(named: "Almost3dot.png")!,
            UIImage(named: "Almost2dot.png")!,
            UIImage(named: "Almost1dot.png")!,
            UIImage(named: "Almost0dot.png")!,
            UIImage(named: "monies3dot.png")!,
            UIImage(named: "monies2dot.png")!,
            UIImage(named: "monies1dot.png")!,
            UIImage(named: "monies0dot.png")!,

        ]

        penjulumLogo.animationDuration = 3
        penjulumLogo.startAnimating()

    }  
}

多个视图控制器无法正常工作(penjulumLogo.animatedImages 旁边的错误:

“线程 1:EXC_BAD_INSTRUCTION(代码=EXC_I386_INVOP,子代码=0x0)):

import UIKit

class ViewController: UIViewController {

let transitionManager = TransitionManager()


@IBOutlet weak var penjulumLogo: UIImageView!

override func viewDidLoad() {
    super.viewDidLoad()


    penjulumLogo.animationImages = [

        UIImage(named: "Storing3dot.png")!,
        UIImage(named: "Storing2dot.png")!,
        UIImage(named: "Storing1dot.png")!,
        UIImage(named: "Storing0dot.png")!,
        UIImage(named: "Encrypted3dot.png")!,
        UIImage(named: "Encrypted2dot.png")!,
        UIImage(named: "Encrypted1dot.png")!,
        UIImage(named: "Encrypted0dot.png")!,
        UIImage(named: "Almost3dot.png")!,
        UIImage(named: "Almost2dot.png")!,
        UIImage(named: "Almost1dot.png")!,
        UIImage(named: "Almost0dot.png")!,
        UIImage(named: "monies3dot.png")!,
        UIImage(named: "monies2dot.png")!,
        UIImage(named: "monies1dot.png")!,
        UIImage(named: "monies0dot.png")!,

    ]

    penjulumLogo.animationDuration = 3
    penjulumLogo.startAnimating()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    // this gets a reference to the screen that we're about to transition to
    let toViewController = segue.destinationViewController as UIViewController

    // instead of using the default transition animation, we'll ask
    // the segue to use our custom TransitionManager object to manage the transition animation

    toViewController.transitioningDelegate = self.transitionManager

}

@IBAction func unwindToViewController(segue: UIStoryboardSegue) {

}

// we override this method to manage what style status bar is shown
override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return self.presentingViewController == nil ? UIStatusBarStyle.Default : UIStatusBarStyle.LightContent
}

@IBAction func returnsegue(sender: UIStoryboardSegue) {
}

}
4

0 回答 0