0

I am wanting to build an animated image into an ImageView for a project that has multiple view controllers. All of the tutorials that I've seen the instructor add an animated view to have a single ViewController. I'm fairly new to coding and am just building a demo.

I have tested applying the code below to ViewController.swift with a single view controller project and it works, but with anything more than one VC it fails. I've posted the code in VC.swift below:

Working code for single view controller:

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()

    }  
}

non-working cold for multiple view controllers (error next to penjulumLogo.animatedImages:

"Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP,subcode=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) {
}

}
Alexey Pichukov
  • 3,377
  • 2
  • 19
  • 22
  • When the app crashes can you type in `bt` in the console and update your answer with what shows up? – kabiroberai Nov 14 '15 at 09:13
  • (lldb) bt * thread #1: tid = 0x6fe68, 0x0000000104b20ab8 libswiftCore.dylib`function signature specialization of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> () + 40, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) – BeeGee001 Nov 16 '15 at 03:54
  • frame #0: 0x0000000104b20ab8 libswiftCore.dylib`function signature specialization of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> () + 40 * frame #1: 0x000000010214fe76 – BeeGee001 Nov 16 '15 at 03:55
  • Transition`Transition.ViewController.viewDidLoad (self=0x00007fd7b1dabfa0)() -> () + 182 at ViewController.swift:22 frame #2: 0x0000000102150dd2 Transition`@objc Transition.ViewController.viewDidLoad (Transition.ViewController)() -> () + 34 at ViewController.swift:0 – BeeGee001 Nov 16 '15 at 03:55
  • frame #3: 0x000000010328d931 UIKit`-[UIViewController loadViewIfRequired] + 1344 frame #4: 0x000000010328dc7d UIKit`-[UIViewController view] + 27 frame #5: 0x000000010316b0c0 UIKit`-[UIWindow addRootViewControllerViewIfPossible] + 61 frame #6: 0x000000010316b7bd UIKit`-[UIWindow _setHidden:forced:] + 302 frame #7: 0x000000010317d020 UIKit`-[UIWindow makeKeyAndVisible] + 43 frame #8: 0x00000001030fa93c UIKit`-[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131 frame #9: 0x0000000103100e15 UIKit`-[UIApplication – BeeGee001 Nov 16 '15 at 03:55
  • _runWithMainScene:transitionContext:completion:] + 1755 frame #10: 0x00000001030fdff0 UIKit`-[UIApplication workspaceDidEndTransaction:] + 188 frame #11: 0x000000010715f7ac FrontBoardServices`-[FBSSerialQueue _performNext] + 192 frame #12: 0x000000010715fb1a FrontBoardServices`-[FBSSerialQueue – BeeGee001 Nov 16 '15 at 03:56
  • _performNextFromRunLoopSource] + 45 frame #13: 0x00000001025ef0a1 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 frame #14: 0x00000001025e4fcc CoreFoundation`__CFRunLoopDoSources0 + 556 frame #15: 0x00000001025e4483 CoreFoundation`__CFRunLoopRun + 867 frame #16: 0x00000001025e3e98 CoreFoundation`CFRunLoopRunSpecific + 488 frame #17: 0x00000001030fd98d UIKit`-[UIApplication _run] + 402 frame #18: 0x0000000103102676 UIKit`UIApplicationMain + 171 frame #19: 0x0000000102152e1d Transition`main + 109 at – BeeGee001 Nov 16 '15 at 03:56

0 Answers0