swift - 如何创建模态动画,其中向上滑动屏幕上半部分,向下滑动屏幕下半部分

标签 swift animation modal-dialog transition

我想创建一个模态动画,其中顶部布局向上滑动,底部布局向下滑动。

类似于此图像:

注:图片取自 Vertical Screen Split Transitions (Animation)

最佳答案

创建一个对象并提供自定义呈现动画:

class TheVendor: NSObject, UIViewControllerTransitioningDelegate {
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return TheAnimator()
    }
}

然后创建动画师:

class TheAnimator: NSObject, UIViewControllerAnimatedTransitioning {
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        // return a duration
    }
    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        // return the custom animation
    }
}

然后,当您呈现时,进行正确的绑定(bind):

presentedViewController.transitioningDelegate = TheVendor()
presentedViewController.modalPresentationStyle = .custom

关于swift - 如何创建模态动画,其中向上滑动屏幕上半部分,向下滑动屏幕下半部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49777489/

相关文章:

ios - 如何使用 'map' 将 Realm 集合更改通知映射到 UITableview 部分?

android - 在带有动画的 fragment 之间切换时出现白色空白屏幕

ios - 我可以用动画围绕中心旋转 UIImage 吗?

javascript - 如何使用语义 ui 制作远程模态

swift - 只获取没有目录的文件的url

带有结构/协议(protocol)的 Swift 多态闭包分派(dispatch)

javascript - 多个悬停实例 jQuery

javascript - 物化滑动选项卡在模态中不起作用

jquery - ASP.net 中隐藏在覆盖层后面的模态 jQuery 对话框

ios - iOS swift UITouch 移动不稳定