需要从左到右再从右到左改变segue过渡
Posted
技术标签:
【中文标题】需要从左到右再从右到左改变segue过渡【英文标题】:Need to change segue transition from left to right and then right to left 【发布时间】:2015-08-04 05:16:31 【问题描述】:我想改变我的代码从左到右的过渡,但是这个 CustomeSegue 只显示从上到下,谢谢!!!
class FirstCustomSegue: UIStoryboardSegue
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(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(0.4, 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)
【问题讨论】:
【参考方案1】:来自您的代码:
你不应该使用宽度而不是高度吗?
// Specify the initial position of the destination view.
secondVCView.frame = CGRectMake(screenWidth, 0.0, screenWidth, screenHeight)
这里也有
// Animate the transition.
UIView.animateWithDuration(0.4, animations: () -> Void in
firstVCView.frame = CGRectOffset(firstVCView.frame, -screenWidth, 0.0)
secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, 0.0)
) (Finished) -> Void in
self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
animated: false,
completion: nil)
【讨论】:
【参考方案2】:将此代码添加到您必须向左移动的按钮操作的源视图控制器中。
func performAnimation()
var mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
// Identifier name for the navigation controller
var initialNavigationController = mainStoryboard.instantiateViewControllerWithIdentifier("initialNavigationController") as! UINavigationController
//Identifier name for the view controller
var mainVC = mainStoryboard.instantiateViewControllerWithIdentifier("startingViewController") as! DestinationViewControllername
initialNavigationController.viewControllers = [mainVC]
self.presentViewController(initialNavigationController, animated: false, completion: nil)
(mainVC as DestinationViewControllername).DestinationRespondSelector()
在您的目标视图控制器中添加以下代码
var TransistionFromSourceVC = false
func DestinationRespondSelector()
TransistionFromSourceVC = true
func ViewAndAnimateIt()
println("here")
TransistionFromSourceVC = false
var mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
// Identifier name for the navigation controller
var mainNavigationController = mainStoryBoard.instantiateViewControllerWithIdentifier("initialNavigationController") as! UINavigationController
//Identifier name for the view controller
var SourceVC = mainStoryBoard.instantiateViewControllerWithIdentifier("SourceViewController") as! SourceVC
mainNavigationController.viewControllers = [SourceVC]
self.view.addSubview(mainNavigationController.view)
self.view.bringSubviewToFront(mainNavigationController.view)
UIView.animateWithDuration(0.3, animations:
mainNavigationController.view.frame.origin.x += self.view.frame.width
) (finished) -> Void in
mainNavigationController.view.removeFromSuperview()
在您的目标视图中添加此代码将出现
override func viewWillAppear(animated: Bool)
if TransistionFromSourceVC
ViewAndAnimateIt()
对源视图控制器和目标视图控制器进行相应的更改。
【讨论】:
我正在使用滑动手势在 viewControllers 之间导航,所以我该如何修改这个:) 谢谢!! 可以在滑动手势中调用performanimation函数。 查看下面的链接,会有帮助的***.com/questions/28675209/…以上是关于需要从左到右再从右到左改变segue过渡的主要内容,如果未能解决你的问题,请参考以下文章