1

应用程序在 iOS 12 上运行良好。但在 iOS 13.1 上崩溃。我认为问题在于设置根视图控制器。

let storyboard = UIStoryboard(name: storyBoard, bundle: nil)
let desiredViewController = storyboard.instantiateViewController(withIdentifier: identifier);
self.window?.switchRootViewController(desiredViewController,animated: animate,options:options)

扩展名是:

extension UIWindow {

func switchRootViewController(_ viewController: UIViewController,  animated: Bool = true, duration: TimeInterval = 0.3, options: UIView.AnimationOptions = .transitionFlipFromRight, completion: (() -> Void)? = nil) {
    guard animated else {
      rootViewController = viewController
      return
    }

    UIView.transition(with: self, duration: duration, options: options, animations: {
      let oldState = UIView.areAnimationsEnabled
      UIView.setAnimationsEnabled(false)
      self.rootViewController = viewController
      UIView.setAnimationsEnabled(oldState)
    }) { _ in
      completion?()
    }
  }
}
4

0 回答 0