【问题标题】:Pop UIViewController with custom "dismiss modal"-like animation使用自定义“关闭模式”类似动画的弹出 UIViewController
【发布时间】:2017-06-20 19:26:33
【问题描述】:

我正在尝试以模拟呈现/关闭UIViewControllers 的方式自定义基于UINavigationController 推送/弹出导航的过渡动画。

以下是标准动画的示例:

  • 到绿屏,
  • 呈现模态橙色屏幕,
  • 关闭模式橙色屏幕和
  • 弹出回到青色屏幕。

我能够获得相同的“从底部向上滑动”推送动画,实现自定义垂直UIStoryboardSegue

困难的部分是实现对应的弹出动画。我能得到的最好的结果如下:

这是相同效果的慢动作版本:

从之前的动画你可以看出它与标准的dismiss modal动画不同主要是因为泡泡糖屏幕不应该从上到下滑动,而应该已经出现在海军屏幕后面流行音乐。

这是我用来创建假解除模式动画的代码:

class FakeModalNavigationController: UINavigationController {

    fileprivate static let unwindToBubblegumScreenSegueID = "unwindToBubblegumScreenSegueID"

    override func unwind(for unwindSegue: UIStoryboardSegue, towardsViewController subsequentVC: UIViewController) {
        if unwindSegue.identifier == type(of: self).unwindToBubblegumScreenSegueID {
            popViewControllerAnimatedFromBottom(subsequentVC)
        }
    }

    fileprivate func popViewControllerAnimatedFromBottom(_ viewControllerToPop: UIViewController) {
        let transition = CATransition()
        transition.duration = 0.25
        transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
        transition.type = kCATransitionPush
        transition.subtype = kCATransitionFromBottom
        view.layer.add(transition, forKey: nil)
        popViewController(animated: false)
    }
}

提前感谢您的回答和cmets!

【问题讨论】:

    标签: ios swift uinavigationcontroller swift3 uistoryboardsegue


    【解决方案1】:

    尝试使用:

    transition.type = kCATransitionReveal
    transition.subtype = kCATransitionFromBottom
    

    【讨论】:

    • 谢谢,这比以前好多了;) 不幸的是,当我执行海军屏幕的假解除模式时,泡泡糖屏幕上仍然有暗影效果。你知道怎么去掉吗?
    猜你喜欢
    • 1970-01-01
    • 2016-10-14
    • 2016-09-15
    • 1970-01-01
    • 2010-11-27
    • 1970-01-01
    • 2016-07-05
    • 1970-01-01
    相关资源
    最近更新 更多