简体   繁体   English

Swift-启动屏幕SIGABRT错误

[英]Swift - launch-screen SIGABRT error

just a real quick issue i'm having with my current swift project. 我目前的快速项目只是一个真正的快速问题。 Essentially; 实质上; i'm trying to implement a combination of tutorials to present an animated launch screen for my application; 我正在尝试实施一系列教程,以为我的应用程序呈现动画启动屏幕; but with the following code I'm getting an error "Thread 1: signal SIGABRT" which I can't seem to figure out the root cause for. 但是,使用以下代码,我收到了错误“线程1:信号SIGABRT”,似乎无法找出根本原因。 The example project I was following was using a tableview as there main home screen with is the only difference between our projects; 我关注的示例项目使用的是表格视图,因为主屏幕显示的是我们项目之间的唯一区别; but I can't find aa justification in the code that would be responsible for proving my errors. 但我无法在代码中找到证明我的错误的理由。 The error resides somewhere within the following as my the remainder of my viewController's have been left blank to try and find the root of the problem. 该错误驻留在下面的某个地方,因为我的viewController的其余部分都留为空白以尝试查找问题的根源。

Here's my app delegate file where the error resides import UIKit 这是错误所在的我的应用程序委托文件,导入UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            // Override point for customization after application launch.

            self.window = UIWindow(frame: UIScreen.main.bounds)
            self.window!.backgroundColor = UIColor(red: 241/255, green: 196/255, blue: 15/255, alpha: 1)
            self.window!.makeKeyAndVisible()

            // rootViewController from StoryBoard
            let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let navigationController = mainStoryboard.instantiateViewController(withIdentifier: "navigationController")
            self.window!.rootViewController = navigationController

            // logo mask
            navigationController.view.layer.mask = CALayer()
            navigationController.view.layer.mask!.contents = UIImage(named: "logo.png")!.cgImage
            navigationController.view.layer.mask!.bounds = CGRect(x: 0, y: 0, width: 60, height: 60)
            navigationController.view.layer.mask!.anchorPoint = CGPoint(x: 0.5, y: 0.5)
            navigationController.view.layer.mask!.position = CGPoint(x: navigationController.view.frame.width / 2, y: navigationController.view.frame.height / 2)

            // logo mask background view
            let maskBgView = UIView(frame: navigationController.view.frame)
            maskBgView.backgroundColor = UIColor.white
            navigationController.view.addSubview(maskBgView)
            navigationController.view.bringSubview(toFront: maskBgView)

            // logo mask animation
            let transformAnimation = CAKeyframeAnimation(keyPath: "bounds")
            transformAnimation.delegate = self as? CAAnimationDelegate
            transformAnimation.duration = 1
            transformAnimation.beginTime = CACurrentMediaTime() + 1 //add delay of 1 second
            let initalBounds = NSValue(cgRect: (navigationController.view.layer.mask!.bounds))
            let secondBounds = NSValue(cgRect: CGRect(x: 0, y: 0, width: 50, height: 50))
            let finalBounds = NSValue(cgRect: CGRect(x: 0, y: 0, width: 2000, height: 2000))
            transformAnimation.values = [initalBounds, secondBounds, finalBounds]
            transformAnimation.keyTimes = [0, 0.5, 1]
            transformAnimation.timingFunctions = [CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut), CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)]
            transformAnimation.isRemovedOnCompletion = false
            transformAnimation.fillMode = kCAFillModeForwards
            navigationController.view.layer.mask!.add(transformAnimation, forKey: "maskAnimation")

            // logo mask background view animation
            UIView.animate(withDuration: 0.1,
                           delay: 1.35,
                           options: UIViewAnimationOptions.curveEaseIn,
                           animations: {
                            maskBgView.alpha = 0.0
            },
                           completion: { finished in
                            maskBgView.removeFromSuperview()
            })

            // root view animation
            UIView.animate(withDuration: 0.25,
                           delay: 1.3,
                           options: UIViewAnimationOptions(),
                           animations: {
                            self.window!.rootViewController!.view.transform = CGAffineTransform(scaleX: 1.05, y: 1.05)
            },
                           completion: { finished in
                            UIView.animate(withDuration: 0.3,
                                           delay: 0.0,
                                           options: UIViewAnimationOptions(),
                                           animations: {
                                            self.window!.rootViewController!.view.transform = CGAffineTransform.identity
                            },
                                           completion: nil
                            )
            })

            return true

    }



    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}

There are two places where your application might crash. 您的应用程序可能在两个地方崩溃。

The first crash possibility is related to instantiating UIViewController from Storyboard . 第一种崩溃可能性与从Storyboard实例化UIViewController有关。 Instead of instantiating from Storyboard you can try some blank UIViewController : 不用从Storyboard实例化,您可以尝试一些空白的UIViewController

let navigationController = UIViewController()
self.window!.rootViewController = navigationController

If it doesn't crash then there are some issues with your Main.storyboard . 如果它没有崩溃,则Main.storyboard可能存在一些问题。

The second place that might cause a crash: 可能导致崩溃的第二个位置:

navigationController.view.layer.mask!.contents = UIImage(named: "logo.png")!.cgImage

Please make sure that your image is fine and it exists in the project. 请确保您的图像很好并且存在于项目中。

Also, you might want to rethink you approach to optional values unwrapping. 此外,您可能想重新考虑采用可选值展开的方法。 Use: 采用:

navigationController.view.layer.mask?.contents = UIImage(named: "logo.png")?.cgImage

Instead of: 代替:

navigationController.view.layer.mask!.contents = UIImage(named: "logo.png")!.cgImage

Edit: 编辑:

I have caught your exception: 我发现了您的例外:

'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier 'navigationController'' “ NSInvalidArgumentException”,原因:“ Storyboard()不包含标识符为“ navigationController”的视图控制器

Please make sure you have a Storyboard ID correctly specified for your navigationController . 请确保您已经为navigationController正确指定了Storyboard ID

在此处输入图片说明

If you need a hint how to catch exceptions, ask in comments. 如果需要提示如何捕获异常,请在注释中提问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM