我有一个包含按钮的导航控制器。当按下此按钮时,我想从右侧滑动新视图,同时当前向外滑动。完全像你有水平滚动scrollview。默认的NavigationController动画似乎只是将新视图推到另一个上面。无论如何要轻易实现这个目标吗?
答案 0 :(得分:0)
在第一个和第二个视图控制器之间实现自定义segue,并在执行方法
中执行此操作override func perform() {
// Assign the source and destination views to local variables.
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(screenWidth, 0 , 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(0.4, animations: { () -> Void in
firstVCView.frame = CGRectOffset(firstVCView.frame,-screenWidth, 0)
secondVCView.frame = CGRectOffset(secondVCView.frame,-screenWidth, 0)
}) { (Finished) -> Void in
self.sourceViewController.presentViewController(self.destinationViewController as UIViewController,
animated: false,
completion: nil)
}
}