我有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)
})
}
}