我正在尝试为多个视图控制器之间的顺序创建自定义动画,以供新用户逐步设置其应用程序。我正在尝试对所有脚本使用相同的自定义UIStoryBoardSegue类(在其中我覆盖了perform func),因为当它们都是相同的动画时,为每个脚本创建一个似乎效率不高。
以下内容第一次起作用,但是以后再使用相同的UIStoryBoardSegue类时,它甚至没有达到断点。
override func perform() {
let firstVCView = source.view!
let secondVCView = destination.view!
let screenWidth = UIScreen.main.bounds.size.width
secondVCView.frame = secondVCView.frame.offsetBy(dx: screenWidth, dy: 0.0)
let superView = firstVCView.superview
superView?.insertSubview(secondVCView, aboveSubview: firstVCView)
UIView.animate(withDuration: 0.35, animations: { () -> Void in
firstVCView.frame = firstVCView.frame.offsetBy(dx: -screenWidth, dy: 0.0)
secondVCView.frame = secondVCView.frame.offsetBy(dx: -screenWidth, dy: 0.0)
}, completion: { (finished) -> Void in
self.source.dismiss(animated: false, completion: nil)
})
}
任何想法都丢失了,还是有更好的方法来实现我正在尝试做的事情?谢谢。
答案 0 :(得分:0)
让我回答您的问题。在动画结束时,您忘记了在源控制器和目标控制器之间建立关系。换句话说,您必须手动显示目的地。
如果您不想从vc堆栈中删除源视图控制器,只需不要关闭源视图控制器并添加self.source.present(self.destination,animation:false,completion:nil),如下所示。
UIView.animate(withDuration: 0.35, animations: { () -> Void in
firstVCView.frame = firstVCView.frame.offsetBy(dx: -screenWidth, dy: 0.0)
secondVCView.frame = secondVCView.frame.offsetBy(dx: -screenWidth, dy: 0.0)
}, completion: { (finished) -> Void in
self.source.present(self.destination, animated: false, completion: nil)
// self.source.dismiss(animated: false, completion: nil)
})
如果要关闭,则必须使用源vc的父vc来推送或显示目标vc,例如UINavigationViewContoller或UITabViewController。希望这能解决您的问题。