【发布时间】:2015-06-22 11:22:47
【问题描述】:
我有 2 个控制器:
- 第一个视图控制器 (1)
- 第二个视图控制器 (2) 嵌入到导航控制器 (2a) 中
( 1 ) -> ( 2a - 2 )
和VC之间的自定义Segue导航:
- 正常的 CustomSegue。从1到2
- 展开 CustomUnwindSegue。从 2 到 1
当我使用正常的转场时: 第二个控制器(包括导航栏!!!)从右侧推送第一个控制器
当我使用 unwind segue 时: 第一个控制器将第二个控制器(没有导航栏!!!仅在导航控制器内查看)推到右侧。导航栏很粘!当导航完成栏消失。
如何使用导航栏推送视图控制器。
我的代码:
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)
})
}
}
【问题讨论】:
标签: ios swift uiviewcontroller uinavigationcontroller uinavigationbar