iOS背景下将应用程序带到前台后的黑屏

问题描述 投票:3回答:1

我正试图从我们的iOS应用程序中删除所有故事板,因为在与Git一起工作时,它们是一个巨大的混乱。

我现在在AppDelegate的application(_:didFinishLaunchingWithOptions:)方法中设置初始ViewController:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    window = UIWindow(frame: UIScreen.main.bounds)
    let launchViewController = LaunchView()
    window!.rootViewController = launchViewController
    window!.makeKeyAndVisible()

    [...]

    return true
}

LaunchView是一个简单的视图控制器,负责将用户路由到登录或主屏幕,具体取决于他/她是否已登录。

在此之前,LaunchView在Main.storyboard中设置为初始值。

我已经从Info.plist文件中删除了这些行:

<key>UIMainStoryboardFile</key>
<string>Main</string>

一切都运行正常,除非我们将应用程序留在后台几个小时没有强行退出(我不确定需要多少时间来重现这个)然后将应用程序带回前景,全黑屏幕显示,好像根控制器消失了。我们必须杀死应用程序并重新打开它才能使用它。

这让我很疯狂,因为它很难重现,因为如果你只在几分钟内将应用程序留在后台,它就能正常工作。我怀疑它与app暂停状态有关,但我不太确定。

你知道问题出在哪里吗?

谢谢!

编辑

也许这与问题有关:在LaunchView上,我使用以下代码将用户发送到主屏幕(如果他已登录):

guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }

let rootVC = UIStoryboard.main.rootViewController
if let snapshot = appDelegate.window?.snapshotView(afterScreenUpdates: true) {

    rootVC.view.addSubview(snapshot);
    appDelegate.window?.rootViewController = rootVC

    UIView.transition(with: snapshot, duration: 0.4, options: .transitionCrossDissolve, animations: {
        snapshot.layer.opacity = 0;
    }, completion: { (status) in
        snapshot.removeFromSuperview()
    })
}
else {
    appDelegate.window?.rootViewController = rootVC
}

iOS有可能在某些时候删除rootViewController吗?

ios swift background foreground
1个回答
-1
投票

原来这个问题与交换效果有关,涉及交换qazxsw pois qazxsw poi时的快照。

我删除了过渡效果,只是改变了window。现在它工作正常!

在代码中,我改变了这个:

rootViewController

对此:

rootViewController

感谢大家的帮助!我希望这个答案对其他人有用。

© www.soinside.com 2019 - 2024. All rights reserved.