ios - 如何从 UIStoryboardSegue 动画中的目的地复制设计?

标签 ios swift uistoryboardsegue

假设我有两个 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/

相关文章:

swift - UITableView 自定义单元格的行高不更新,Swift iOS8

Swift:在模态中强制显示导航栏

ios - 在 UITableView 中切换选项卡时防止从内存中删除覆盖 Controller

ios - 禁用 segue 动画

ios - 我真的需要导航 Controller 吗?

ios - 更改导航栏中后退按钮的标题

ios - 带有 PageTabViewStyle 的 TabView 上的edgesIgnoringSafeArea 不起作用

ios - 如何让 Alexa 在我的 iOS 应用程序上运行?

iphone - 每个屏幕的 NavigationController 自定义后退按钮

ios - 如何以编程方式添加多个导航 Controller ?