【发布时间】:2017-09-19 20:19:48
【问题描述】:
所以我有 2 个视图控制器和一个导航控制器。当点击屏幕时,第一个 VC 切换到第 2 个 VC,并且有一个后退按钮可以让 segue 展开以返回到第一个 VC。
我不喜欢 segues 的垂直动画,所以(在一些帮助下)我创建了自定义的水平动画。
第一个 VC 非常适合动画从右向左滑动。但是一旦这样做了,第二个 VC 就不想放松了(第二个 VC 应该从左到右)。
我确实收到了这个警告..
警告:尝试在 TestApp.HomeViewController: 0x7fce20410030 上呈现 UINavigationController: 0x7fce2082b000,其视图不在窗口层次结构中!
另外,如果我从第一个 VC segue 中获取脚本,那么我可以通过适当的动画从第二个 VC 中放松。
这是转场的代码:
第一个 VC
@IBAction func performSegue(_ sender: Any) {
if shouldPerformSegue(withIdentifier: "segue", sender: Any?.self) {
performSegue(withIdentifier: "segue", sender: nil)
}
}
@IBAction func unwindToHomeView(segue: UIStoryboardSegue) {
}
override func unwind(for unwindSegue: UIStoryboardSegue, towardsViewController subsequentVC: UIViewController) {
let segue = SegueFromLeft(identifier: unwindSegue.identifier, source: unwindSegue.source, destination: unwindSegue.destination)
segue.perform()
}
从右到左的动画
let dst = self.destination
let src = self.source
let containerView = src.view.superview
dst.view.transform = CGAffineTransform(translationX: src.view.frame.size.width, y: 0)
containerView?.addSubview(dst.view)
UIView.animate(withDuration: 0.25, delay: 0.0, options: UIViewAnimationOptions.curveEaseInOut, animations: {
dst.view.transform = CGAffineTransform(translationX: 0, y: 0)
}, completion: { success in
src.present(dst, animated: false, completion: nil)
})
从左到右的动画
let dst = self.destination
let src = self.source
src.view.superview?.insertSubview(dst.view, at: 0)
UIView.animate(withDuration: 0.25, delay: 0.0, options: UIViewAnimationOptions.curveEaseInOut, animations: {
src.view.transform = CGAffineTransform(translationX: -src.view.frame.size.width, y: 0)
}, completion: { success in
src.dismiss(animated: false, completion: nil)
})
任何帮助将不胜感激。
【问题讨论】:
-
所以.. 我取消了动画。我的动画的解决方案相当简单。只需切换导航器的位置,并将其作为初始视图控制器就可以了。修复任何动画或推送问题。
-
不确定我是否应该放下我的解决方案,因为它并不能真正帮助回答我的具体问题。
标签: ios swift xcode segue unwind-segue