简介
使用 EasyPopup,您可以轻松地将视图/UViewController 转换为弹出窗口。
scale | rightToleft | upTodown | scale | leftToRight | upTodown |
---|---|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
安装
EasyPopUp 通过 CocoaPods 提供。只需将以下内容添加到您的 Podfile 中
use_frameworks!
target '<Your Target Name>'
pod 'EasyPopUp'
演示
您可以在示例文件夹中轻松找到并运行演示应用程序。
用法
EasyPopup 由两个类组成;一个用于视图,另一个用于 ViewControllers。
视图用法
对于视图用法,您只需传递您视图的父视图和您想要作为弹出窗口的视图。您可以提供自定义配置文件(下面将详细解释)来自定义转换、阴影、角落等。
public init(superView: UIView, viewTopop view: UIView, config: EasyPopupConfig = default)
// example
let popupView = EasyPopup(superView: self.view, viewTopop: viewToPop)
然后您可以使用以下方法显示弹出窗口
public func Showpopup(completion: ((Bool) -> Void)? = nil)
// example
popupView.showPopup { (isfinished) in
// do after showing popup
}
您可以直接显示弹出窗口,或者使用完成处理程序在弹出窗口动画完成后执行任何操作。
关于关闭弹出窗口:
public func removePopup(completion: ((Bool) -> Void)? = nil)
// example
popupView.removePopup { (isfinished) in
// do after dismissing popup
}
ViewController 使用方法
对于观音方法的使用,您的viewController必须遵守 EasyPopUpViewControllerDatasource
协议,您应该传递您要弹出的视图(在您的viewController中)。注意,您的视图应在您的viewController中设置约束。
public init(sourceViewController: UIViewController, destinationViewController: UIViewController, config: EasyPopupConfig = default)
}
sourceViewController
:要出现弹出菜单的源viewController。 destinationViewController
:要显示的弹出viewController。 config
:用于提供自定义阴影、转场、圆角等的EasyPopup配置文件。
用法示例
在您的弹窗viewController类中
class popViewController: UIViewController {
@IBOutlet weak var popupContentView: UIView!
}
extension popViewController : EasyPopUpViewControllerDatasource {
var popupView: UIView {
return popupContentView
}
}
在您的源viewController中
let popupVC = self.storyboard?.instantiateViewController(withIdentifier: "popViewController") as! popViewController
let easePopUp = EasyViewControllerPopup(sourceViewController: self, destinationViewController: popupVC )
要显示弹窗,请使用showVCAsPopup
方法
easePopUp.showVCAsPopup()
要关闭,只需简单地关闭viewController。请放心,EasyPopup已经覆盖了默认的转场效果。
如果使用说明没有帮助,请运行示例项目。它会对你的开发有所帮助
自定义
Easypopup使用配置来自定义转场、模糊效果、圆角和阴影。
您可以传递配置弹窗对象
popUpView.config = popUpConfig // or pass it via initializar
配置包含以下属性
public var shadowEnabled : Bool // popup shadow
public var cornerRadius: CGFloat // the cornerRadius of popup
public var dimBackground : Bool // dim the backView of popup
public var blurBackground : Bool // whether contain blur or not
public var autoDismiss: Bool // the autoDismiss that dimiss popup when clicking on outside of view
public var animationType: AnimationType // animationType enum
public var animaionDuration : TimeInterval // animaionDuration
public var animtionOptions: UIViewAnimationOptions // UIViewAnimationOptions
public var blurRadius: CGFloat /// Blur Radius you should enable the blurBackground variable to work
public var blurTrackingMode : TrackingMode /// DynamicBlurView trackingMode
EasyPopup使用DynamicBlurView
进行背景模糊。动画类型是弹出动画的方式
public enum AnimationType {
case scale
case upToDown
case downToUp
case immediate
case rightToleft
case leftToright
}
许可证
EasyPopup受MIT许可证的约束。有关更多信息,请参阅LICENSE文件。