我不确定我的应用程序委托中发生了什么我完成了此代码显示我的服务视图

  func showServiceStartView()
    {
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let secondViewController = storyBoard.instantiateViewControllerWithIdentifier("SERVICE_START_VC_ID")
        self.window!.rootViewController = secondViewController
        self.window!.makeKeyAndVisible()
    }

但它给了我奇怪的行为。当视图切换时,它会在几秒钟内显示额外的覆盖,然后消失。但我不想要额外的覆盖。
http://giphy.com/gifs/l0MYFCQ3LwV8r90m4
我正在流动这个Programmatically set the initial view controller using Storyboards

最佳答案

这个额外的覆盖来自上一个屏幕。如果你不想那样的覆盖,你必须使用自定义转换。下面是交换根视图控制器的代码
对于Swift 3.0:

    func changeRootViewController(with identifier:String!) {
    let storyboard = self.window?.rootViewController?.storyboard
    let desiredViewController = storyboard?.instantiateViewController(withIdentifier: identifier);

    let snapshot:UIView = (self.window?.snapshotView(afterScreenUpdates: true))!
    desiredViewController?.view.addSubview(snapshot);

    self.window?.rootViewController = desiredViewController;

    UIView.animate(withDuration: 0.3, animations: {() in
      snapshot.layer.opacity = 0;
      snapshot.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5);
      }, completion: {
        (value: Bool) in
        snapshot.removeFromSuperview();
    });
  }

对于Swift 2.2:
 func changeRootViewControllerWithIdentifier(identifier:String!) {
let storyboard = self.window?.rootViewController?.storyboard
let desiredViewController = storyboard?.instantiateViewControllerWithIdentifier(identifier);

let snapshot:UIView = (self.window?.snapshotViewAfterScreenUpdates(true))!
desiredViewController?.view.addSubview(snapshot);

self.window?.rootViewController = desiredViewController;

UIView.animateWithDuration(0.3, animations: {() in
  snapshot.layer.opacity = 0;
  snapshot.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5);
  }, completion: {
    (value: Bool) in
    snapshot.removeFromSuperview();
});

}

关于ios - 切换 View Controller 可提供额外的覆盖,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41221240/

10-10 20:29