假设我有两个 UIViewController,我们可以将它们称为 ControllerOne 和 ControllerTwo。
在我的应用程序中,我在 ControllerOne 和 ControllerTwo 之间创建了一个自定义 UIStoryboardSegue 动画。我想用动画创建的效果是,感觉就像 ControllerTwo 的一部分滑到 ControllerOne 上,这样两个 UIViewController 之间的转场似乎就不是转场了。
从这一点来看,我不知道哪种方法是最好的。 ControllerTwo 的设计是通过 Storyboard设置的,但我如何获得它?
(我所知道的是,我无法将 ControllerTwo 中的值复制到 segue 中,因为它们尚未设置,因此会引发错误。)
最佳答案
通常我们通过 UIViewController 类中的这个函数 prepareForSegue
传递数据
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "idFirstSegue" {
let secondViewController = segue.destinationViewController as SecondViewController
//secondViewController.message = ...
}
}
您还可以在 UIStoryboardSegue 类的子类中重写 perform
函数,
这是代码:
override func perform() {
var firstVC = self.sourceViewController as UIViewController!
var secondVC = self.destinationViewController as UIViewController!
//Then copy design from destination
}
The article我认为适合你。
关于ios - 如何从 UIStoryboardSegue 动画中的目的地复制设计?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45897315/