美文网首页解决方案
基于UIPresentationController的封装

基于UIPresentationController的封装

作者: 大泡沫 | 来源:发表于2019-09-30 14:51 被阅读0次

    效果图

    screenshot.gif

    简单介绍

    • 基于UIPresentationController的封装,支持多种转场效果,还可轻松自定义转场动画

    • 使用方法:
      需要present的ViewController遵守PresentedViewType协议即可:

    class AlertViewController: UIViewController, PresentedViewType {
    
        var component: PresentedViewComponent
    
        override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
            component = PresentedViewComponent(contentSize: CGSize(width: 260, height: 240))
            super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        }
    
        required init?(coder aDecoder: NSCoder) {
            component = PresentedViewComponent(contentSize: CGSize(width: 260, height: 240))
            super.init(coder: aDecoder)
        }
    }
    

    要自定义转场效果及其他,只需要设置component即可:

        ....
    
        let alertVC = getAlertVC()
        var component = PresentedViewComponent(contentSize: CGSize(width: 260, height: 240))
        component.destination = .center
        component.presentTransitionType = .custom(animation: CrossZoomAnimation(scale: 0.01, options: .spring(duration: 0.5, delay: 0, damping: 0.4, velocity: 10), origin: .center))
        component.dismissTransitionType = .crossZoom
        component.keyboardTranslationType = .compressInputView
        component.keyboardPadding = 60
        alertVC.component = component
        presentViewController(alertVC)
    
        ....
    

    更具体的用法请下载 Demo查看。

    相关文章

      网友评论

        本文标题:基于UIPresentationController的封装

        本文链接:https://www.haomeiwen.com/subject/kszcpctx.html