如果您正在苦苦寻找一种在 iOS 设备上将视图或视图控制器显示为弹窗的方法,那么这个 pod 就是为您准备的。 使用 EzPopup,您可以轻松显示弹窗,如下所示:
要运行示例项目,请克隆 repo,然后首先从 Example 目录运行 pod install
。
ImageScrollView
版本)。dependencies: [
.package(url: "https://github.com/huynguyencong/EzPopup.git", .upToNextMajor(from: "1.0.0"))
]
或者
File > Swift Packages > Add Package Dependency 添加 https://github.com/huynguyencong/EzPopup.git 选择 "Up to Next Major" 并设置为 "1.0.0"
EzPopup 可通过 CocoaPods 获得。 要安装它,只需将以下行添加到您的 Podfile 中
pod 'EzPopup'
使用弹窗视图控制器非常简单
首先,使用您要显示的视图或视图控制器初始化一个 PopupViewController
。
// init YourViewController
let contentViewController = ...
// Init popup view controller with content is your content view controller.
// You can let your content view determine pop up size by using its intrinsic size by setting popupWidth and popupHeight nil.
// You can also set position by the position param. If you want show a pop up below a view, use .offsetFromView for position param.
let popupVC = PopupViewController(contentController: contentViewController, popupWidth: 100, popupHeight: 200)
// show it by call present(_ , animated:) method from a current UIViewController
present(popupVC, animated: true)
可选:您可以自定义 PopupViewController
的某些属性。 例如
popupVC.backgroundAlpha = 0.3
popupVC.backgroundColor = .black
popupVC.canTapOutsideToDismiss = true
popupVC.cornerRadius = 10
popupVC.shadowEnabled = true
huynguyencong, conghuy2012@gmail.com
EzPopup 在 MIT 许可证下可用。 有关更多信息,请参见 LICENSE 文件。