切换rootviewcontroller后,应用程序在iOS 13上崩溃

时间:2019-10-30 13:58:10

标签: ios13 xcode11.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?()
    }
  }
}

0 个答案:

没有答案