0

我有2個控制器:夫特定製放鬆Segue公司從導航控制器向視圖控制器

  • 首先視圖控制器(1)
  • 第二視圖控制器(2)嵌入在導航控制器(2A)

(1) - >(2A - 2)

和自定義VC之間Segue公司導航:

  • 正常CustomSegue。從1到2
  • 展開CustomUnwindSegue。從2到1

當我使用正常賽格瑞: 第二控制器(包括導航欄!!!)從右側

推第一控制器當我使用退繞賽格瑞: 第一控制器推第二控制器(沒有導航欄!!!只能在導航控制器內查看)到右側。導航欄很粘!導航完成條消失時。

如何將View Controller與導航欄一起推送。

我的代碼:

class CustomSegue: UIStoryboardSegue { 

    override func perform() { 

     let toViewController: UIViewController = self.destinationViewController as! UIViewController 
     let fromViewController: UIViewController = self.sourceViewController as! UIViewController 

     let containerView: UIView? = fromViewController.view.superview 
     let screenBounds: CGRect = UIScreen.mainScreen().bounds 

     let finalToFrame: CGRect = screenBounds 
     let finalFromFrame: CGRect = CGRectOffset(finalToFrame, -screenBounds.size.width, 0) 

     toViewController.view.frame = CGRectOffset(finalToFrame, screenBounds.size.width, 0) 
     containerView?.addSubview(toViewController.view) 

     UIView.animateWithDuration(0.5, animations: { 

      toViewController.view.frame = finalToFrame 
      fromViewController.view.frame = finalFromFrame 

      }, completion: { finished in 
       let fromVC: UIViewController = self.sourceViewController as! UIViewController 
       let toVC: UIViewController = self.destinationViewController as! UIViewController 
       fromVC.presentViewController(toVC, animated: false, completion: nil) 
     }) 
    } 
} 

class CustomUnwindSegue: UIStoryboardSegue { 

    override func perform() { 

     let toViewController: UIViewController = self.destinationViewController as! UIViewController 
     let fromViewController: UIViewController = self.sourceViewController as! UIViewController 

     let containerView: UIView? = fromViewController.view.superview 
     let screenBounds: CGRect = UIScreen.mainScreen().bounds 

     let finalToFrame: CGRect = screenBounds 
     let finalFromFrame: CGRect = CGRectOffset(finalToFrame, screenBounds.size.width, 0) 

     toViewController.view.frame = CGRectOffset(finalToFrame, -screenBounds.size.width, 0) 
     containerView?.addSubview(toViewController.view) 

     UIView.animateWithDuration(0.5, animations: { 

      toViewController.view.frame = finalToFrame 
      fromViewController.view.frame = finalFromFrame 

      }, completion: { finished in 
       let fromVC: UIViewController = self.sourceViewController as! UIViewController 
       let toVC: UIViewController = self.destinationViewController as! UIViewController 
       fromVC.dismissViewControllerAnimated(false, completion: nil) 
     }) 
    } 
} 

回答

0

在正向SEGUE,你是從VC1動畫到VC2A,這將是SEGUE的目的地。動畫VC2a也會使VC2出現,因爲VC2a將其作爲其視圖的一部分。因此,UINavigationBar和VC2都會滑入。

在反向循環中,您正在從VC2動畫到VC1。 VC2的view沒有覆蓋整個屏幕,因爲有些被UINavigationBar佔用。將VC2的視圖設置爲側面並將其替換爲VC1,並且完成後,您將dismissViewControllerAnimated導致VC2a在沒有動畫的情況下消失。

而不是在反向賽格動畫VC2的視圖,您需要再次動畫VC2a的視圖。這應該帶着VC2一起。我還沒有試過這個代碼,但是像這樣:

UIView.animateWithDuration(0.5, animations: { 
     toViewController.view.frame = finalToFrame 
     VC2a.view.frame = finalFromFrame 
    } 
相關問題