I have 2 controllers:
- First view controller (1)
- Second view controller (2) embed in Navigation controller (2a)
( 1 ) -> ( 2a - 2 )
And custom Segue navigation between VC:
- normal CustomSegue. From 1 to 2
- unwind CustomUnwindSegue. From 2 to 1
When I use normal segue: Second controller (including navigation bar!!!) push First controller from right side
When I use unwind segue: First controller push Second controller (without navigation bar!!! Only view inside Navigation controller) to right side. Navigation bar is sticky! When navigation completed bar disappears.
How can I push View Controller with Navigation bar.
My code:
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)
})
}
}