如何像关闭样式一样从顶部以模式方式呈现视图控制器



如何从顶部以模式呈现视图控制器?我想像关闭样式一样展示我的视图控制器...我已经尝试过CATransition,但它没有给我相同的动画持续时间。有什么帮助吗?

CATransition方法:

let vc = storyboard?.instantiateViewController(withIdentifier: "DownloadAudio") as! DownloadAudioViewController 
let transition = CATransition() 
transition.duration = 0.25 
transition.type = kCATransitionPush 
transition.subtype = kCATransitionFromBottom 
transition.timingFunction = CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseInEaseO‌​ut) 
view.window!.layer.add(transition, forKey: kCATransition) 
present(vc, animated: false, completion: nil)

您需要通过创建一个对象(如下所示(来创建自定义演示文稿,该对象可以自动显示和关闭动画对象:

class PresentationObjectVendor: NSObject, UIViewControllerTransitioningDelegate {
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return CustomDropPresentAnimator()
    }
    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return CustomDropDismissAnimator()
    }
}

然后创建这些动画对象,如下所示:

// present animator
class CustomDropPresentAnimator: NSObject, UIViewControllerAnimatedTransitioning {
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        // return a time interval
    }
    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        // perform animations
    }
}
// dismiss animator
class CustomDropDismissAnimator: NSObject, UIViewControllerAnimatedTransitioning {
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        // return a time interval
    }
    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        // perform animations
    }
}

相关内容

  • 没有找到相关文章

最新更新