Ios 斯威夫特:定制赛格后,我如何保留嵌入式导航控制器?
我正在尝试从嵌入导航控制器的视图控制器设置自定义segue。当我使用show segue时,一切正常,导航栏仍如预期的那样。但是,当我尝试使用自定义segue类时,导航栏消失了。检查后,post custom segue view控制器中不存在导航控制器。因此,问题似乎来自使用自定义segue:如何使用自定义segue保持在导航控制器中?这是我的自定义segue代码,其目的是使segue具有从上到下的滑动效果:Ios 斯威夫特:定制赛格后,我如何保留嵌入式导航控制器?,ios,swift,uinavigationcontroller,uistoryboardsegue,Ios,Swift,Uinavigationcontroller,Uistoryboardsegue,我正在尝试从嵌入导航控制器的视图控制器设置自定义segue。当我使用show segue时,一切正常,导航栏仍如预期的那样。但是,当我尝试使用自定义segue类时,导航栏消失了。检查后,post custom segue view控制器中不存在导航控制器。因此,问题似乎来自使用自定义segue:如何使用自定义segue保持在导航控制器中?这是我的自定义segue代码,其目的是使segue具有从上到下的滑动效果: class FirstCustomSegue: UIStoryboardSegue
class FirstCustomSegue: UIStoryboardSegue {
override func perform() {
var firstVCView = self.sourceViewController.view as UIView!
var secondVCView = self.destinationViewController.view as UIView!
// Get the screen width and height.
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height
// Specify the initial position of the destination view.
secondVCView.frame = CGRectMake(0.0, -screenHeight, screenWidth, screenHeight)
// Access the app's key window and insert the destination view above the current (source) one.
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(secondVCView, aboveSubview: firstVCView)
// Animate the transition.
UIView.animateWithDuration(1, animations: { () -> Void in
firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, screenHeight)
secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, screenHeight)
}) { (Finished) -> Void in
self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
animated: false,
completion: nil)
}
}
}我认为对于自定义序列,必须执行
navigationController.pushViewController()
操作,以使新VC显示在旧NC堆栈上。我看不出有什么办法可以通过定制segue实现这一点。然而,我确实看到了一种让事情看起来像是真的发生的方法:
class FirstCustomSegue: UIStoryboardSegue {
override func perform() {
let firstVCView = self.sourceViewController.view as UIView!
let secondVCView = self.destinationViewController.view as UIView!
// Get the screen width and height.
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height
// Specify the initial position of the destination view.
secondVCView.frame = CGRectMake(0.0, -screenHeight, screenWidth, screenHeight)
// make a UIView which looks like the sourceViewController's view,
// and add it to the destinationViewcontrollers's view,
// in the right place so it looks as though it does not move
let v1 = firstVCView.snapshotViewAfterScreenUpdates(false)
v1.frame = CGRectMake(0, screenHeight, screenWidth, screenHeight)
secondVCView.addSubview(v1)
// push the destination VC without animation
// but it looks the same as the first so it seems as though nothing has happened.
self.sourceViewController.navigationController?.pushViewController(self.destinationViewController, animated: false)
// Animate the transition.
UIView.animateWithDuration(1, animations: { () -> Void in
secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, screenHeight)
}) { (Finished) -> Void in
v1.removeFromSuperview()
}
}
}
这会使
pushViewController
不带动画,然后通过将源视图的快照临时放置到第二个视图上,使其看起来像动画一样。它在我的iPad上看起来还可以。这是与相同的问题,但还没有回答。有趣的问题,我还不确定我是否正确理解它,这是最好的一种!谢谢你的提醒!