As custom Popup view is showing perfectly But navigation view back button is also enable while showing popup view. So, Is it possible to show custom popup view on top of view hierarchy like we normally do in swift like this
guard let window : UIWindow = UIApplication.shared.windows.filter({$0.isKeyWindow}).first else {return}
var presentVC = window.rootViewController
while let next = presentVC?.presentedViewController {
presentVC = next
}
Source Code:
struct LogInView: View {
@State private var email: String = ""
@State private var isShowPopup: Bool = false
@Binding var showSelfView: Bool
var body: some View {
ZStack {
VStack(alignment: .leading, spacing: 30) {
// Top
VStack(alignment: .leading, spacing: 10) {
Text("Login")
.font(.title).bold()
.foregroundColor(Design.Theme.PrimaryTextColor)
Text("Please enter your password to log in to your VaultsPay account")
.font(.headline)
.fontWeight(.regular)
.foregroundColor(Design.Theme.SecondaryTextColor)
}
// TextFields
VStack(spacing: 15) {
TextField("Email", text: $email)
.keyboardType(.emailAddress)
.textFieldStyle(.plain)
.padding(.horizontal, 12)
.frame(height: 55)
.background(
Design.Theme.TextFieldBackgroundColor.cornerRadius(15)
)
TextField("Password", text: $email)
.keyboardType(.emailAddress)
.textFieldStyle(.plain)
.frame(height: 55)
.padding(.horizontal, 12)
.background(
Design.Theme.TextFieldBackgroundColor.cornerRadius(15)
)
}
Button(action: {
withAnimation {
self.isShowPopup.toggle()
}
}) {
Text("Login")
.font(.title3).bold()
.foregroundColor(Design.Theme.WhiteTextColor)
.frame(height: 55)
.frame(maxWidth: .infinity)
.background(Design.Theme.SecondaryBackgroundColor)
.cornerRadius(15)
.opacity(0.4)
}
HStack(alignment: .center) {
Button(action: {
self.showSelfView = false
}) {
Text("Forgot Password?")
.font(.headline).bold()
.foregroundColor(Design.Theme.TertiaryTextColor)
.frame(width: 200, height: 25)
}
.frame(maxWidth: .infinity)
}
Spacer()
} //: Main VSTACK
.padding(.horizontal)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
Image(Design.Icon.AppLogo)
.scaledToFit()
}
}
if self.isShowPopup {
GeometryReader { _ in
ConfirmationDialog()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(.horizontal, 35)
}
.background(
Color.black.opacity(0.65)
.edgesIgnoringSafeArea(.all)
.onTapGesture {
withAnimation {
self.isShowPopup.toggle()
}
}
)
}
}
}
Source code to handle custom Popup view:
if self.isShowPopup {
GeometryReader { _ in
ConfirmationDialog()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(.horizontal, 35)
}
.background(
Color.black.opacity(0.65)
.edgesIgnoringSafeArea(.all)
.onTapGesture {
withAnimation {
self.isShowPopup.toggle()
}
}
)
}
Problem Screenshot:
Thanks in advance. Looking forward to your help.
2条答案
按热度按时间z2acfund1#
在
VStack
的底部,加入修饰词.navigationBarBackButtonHidden()
。7lrncoxx2#
我知道这是一个老问题,但搜索了这么多的实现弹出在swift用户界面和每件事,我发现有问题,无论是导航栏,返回按钮的屏幕大小,除非我发现以下链接. https://johncodeos.com/how-to-create-a-popup-window-with-swiftui/
简单地创建一个弹出视图,并根据绑定变量显示和隐藏它。在ZStack中调用这个弹出视图,如下所示-很高兴找到这个!!!希望它也能帮助其他人!!!