滚动视图,如导航控制器的过渡[重复]
Posted
技术标签:
【中文标题】滚动视图,如导航控制器的过渡[重复]【英文标题】:Scrollview like transition with navigationController [duplicate] 【发布时间】:2017-12-14 17:56:21 【问题描述】:我有一个包含按钮的导航控制器。按下此按钮时,我想从右侧滑入新视图,同时当前向左滑出。就像你有水平滚动滚动视图一样。默认 NavigationController 动画似乎只是将新视图推到另一个之上。有没有办法轻松实现这一点?
【问题讨论】:
另外,你可以找到here 一些很酷的例子来说明如何实现自定义转换 【参考方案1】:在第一个和第二个视图控制器之间实现自定义 segue 并在 perform 方法中执行此操作
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)
【讨论】:
我没用storyboard,还能用吗? Storyboard 需要在第一个和第二个控制器之间创建自定义 segue,您将在其中为其分配包含 perform 方法的自定义 segue 类以上是关于滚动视图,如导航控制器的过渡[重复]的主要内容,如果未能解决你的问题,请参考以下文章