ios - 无法为多个 Segue 重用自定义 StoryboardSegue 类

标签 ios swift xcode swift3

我正在尝试为多个 View Controller 之间的转场创建自定义动画,以便新用户逐步设置他们的应用程序。我尝试对所有转场使用相同的自定义 UIStoryBoardSegue 类(我在其中重写执行函数),因为当它们都是相同的动画时,为每个转场创建一个似乎效率很低。

以下内容第一次有效,但当我稍后再次使用相同的 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)
    })
}

知道缺少什么,或者有更好的方法来实现我想要做的事情吗?谢谢。

最佳答案

我来回答你的问题吧。在动画结束时,您忘记了源 Controller 和目标 Controller 之间建立的关系。换句话说,您必须手动显示您的目的地。

如果您不想从 vc 堆栈中删除源 View Controller ,请不要关闭源 View Controller 并添加 self.source.present(self.destination,animated: 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。希望这能解决您的问题。

关于ios - 无法为多个 Segue 重用自定义 StoryboardSegue 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52463610/

相关文章:

ios - 简单的快速秒表不起作用

iOS 到 Node.js 后端 SSL 握手失败

objective-c - 如何在iOS中以编程方式添加UITabBarItem的标识符类型?

ios - 在 iTunes Connect 中创建用户时出错 : Invalid Year

ios - swift - Twilio 视频聊天 - 卡住时发出警报

swift - 设置剪辑到边界的图像溢出边界

arrays - 延迟循环数组 - Swift

ios - 如何更新另一个 UIViewController 上的进度 View - SWIFT?

ios - Xcode 6.1 重复目标的不同 "deployment info"部分

ios - 安装任何新的 Cocoapod 都会导致构建失败