解决方案

基于UIPresentationController的封装

2019-09-30  本文已影响0人  大泡沫

效果图

screenshot.gif

简单介绍

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查看。

上一篇下一篇

猜你喜欢

热点阅读