Ios 推送和弹出序列动画的反向方向?
我在根视图控制器的左侧有一个按钮,该按钮触发到另一个视图控制器的按下顺序。我希望推序列是动画从左侧滑动到右侧;我还希望pop动画(对于此视图控制器)从右向左 我能够使用以下代码为推送创建自定义序列,以制作所需的动画:Ios 推送和弹出序列动画的反向方向?,ios,swift,uinavigationcontroller,segue,Ios,Swift,Uinavigationcontroller,Segue,我在根视图控制器的左侧有一个按钮,该按钮触发到另一个视图控制器的按下顺序。我希望推序列是动画从左侧滑动到右侧;我还希望pop动画(对于此视图控制器)从右向左 我能够使用以下代码为推送创建自定义序列,以制作所需的动画: import UIKit class LeftToRightSegue: UIStoryboardSegue { override func perform() { let src: UIViewController = self.sourceViewC
import UIKit
class LeftToRightSegue: UIStoryboardSegue {
override func perform() {
let src: UIViewController = self.sourceViewController
let dst: UIViewController = self.destinationViewController
let finalFrame = src.view.bounds
let initalFrame = CGRect(x: -finalFrame.width, y: 0, width: finalFrame.width, height: finalFrame.height)
dst.view.frame = initalFrame
UIView.animateWithDuration(0.25, animations: { dst.view.frame = finalFrame })
src.navigationController!.pushViewController(dst, animated: false)
}
}
然后,我尝试使用以下代码为pop创建一个segue:
import UIKit
class RightToLeftSegue: UIStoryboardSegue {
override func perform() {
let src: UIViewController = self.sourceViewController
let dst: UIViewController = self.destinationViewController
let finalFrame = src.view.bounds
let initalFrame = CGRect(x: 2*finalFrame.width, y: 0, width: finalFrame.width, height: finalFrame.height)
dst.view.frame = initalFrame
UIView.animateWithDuration(0.25, animations: { dst.view.frame = finalFrame })
dst.navigationController!.popViewControllerAnimated(false)
}
}
但我得到了一个错误:
fatal error: unexpectedly found nil while unwrapping an Optional value
在生产线上:
dst.navigationController!.popViewControllerAnimated(false)
因为导航控制器(出于某种原因)为零
我所希望的是推送和弹出的动画被反转,不管它是否与自定义序列。有人知道我如何修复这个实现,或者创建一个更好的实现吗
更新:我为流行音乐找到了一个非常黑客的解决方案:
let main = self.navigationController!.viewControllers.first!
self.navigationController!.viewControllers.removeAtIndex(0)
self.navigationController!.pushViewController(main, animated: true)
self.navigationController!.viewControllers.removeAtIndex(0)
我绝对愿意接受更好的解决方案