轻松地在 SwiftUI 上从任何子视图以全屏方式展示不同的弹窗。
![]() |
![]() |
![]() |
Swift Package Manager
https://github.com/Jnis/ZPopupPresenter.git
import ZPopupPresenter
struct ContentView: View {
let zPopupPresenterModel = ZPopupPresenterModel() // 1.1. shared model
var body: some View {
MyView()
.environmentObject(zPopupPresenterModel) // 1.2. inject model for subviews
.overlay {
ZPopupPresenterView(model: zPopupPresenterModel) // 2. popups place
}
}
}
showPopup
方法,并用 AnyView( ... )
包装您的视图close
闭包来移除弹窗struct MyView: View {
@EnvironmentObject var zPopupPresenterModel: ZPopupPresenterModel // shared model
var body: some View {
VStack {
Button("Show Popup", action: {
zPopupPresenterModel.showPopup({ close in // 3.
AnyView(
DemoPopup1View(closeBlock: close) // 4.
)
})
})
}
}
}
您可以在 /Examples
文件夹中找到更多示例。
MIT