swift - Swift:视图在实际设备上自行消失
问题描述
我有两个视图(AnimalDetailView 和 ReportView),它们在点击 MapView 上的按钮和注释时出现。我通过导航链接浏览视图。
当我在模拟器上运行应用程序时没有问题。但是,当我在我的实际设备上运行它时,DetailsView 和 ReportView 都会在出现后立即消失。
这背后的原因是什么?
这就是我的 NavigationView 在 MapView 上的设置方式。
ZStack {
// NAVIGATION LINK FOR ANIMAL DETAIL VIEW
NavigationLink(destination: AnimalDetailView(animalAnnotation: animalAnnotation), tag: "animal_detail_view_tag", selection: $annotaionSelection) { EmptyView()
}
MapModel().onAnnotationTapped(perform: { annotation in
// HERE YOU GET ANNOTATION TAPPED CALLBACKS
if annotation is AnimalAnnotation {
self.animalAnnotation = annotation as? AnimalAnnotation
annotaionSelection = "animal_detail_view_tag"
}else if annotation is ShelterAnnotation {
self.shelterAnnotation = annotation as? ShelterAnnotation
showingAlert = true
}
}).edgesIgnoringSafeArea(.all)
.alert(isPresented: $showingAlert) {
Alert(title: Text(self.shelterAnnotation?.title ?? ""),
message: Text("Veteriner veya barınağı arayarak yaralı hayvanın durumunu bildir."),
primaryButton: .default(Text("Barınağı ara"),
action: {callNumber(phoneNumber: "\(self.shelterAnnotation?.number ?? 0)" )}),
secondaryButton: .cancel(Text("İptal")))
}
NavigationLink(
destination: ReportView(),
label: {
ZStack {
RoundedRectangle(cornerRadius: 5)
.frame(width: 300, height: 60, alignment: .center)
.foregroundColor(Color("AnbulanceBlue"))
Text("YARALI HAYVAN BİLDİR")
.foregroundColor(.white)
.font(.system(size: 20))
.fontWeight(.bold)
}
}).offset(y: 260)
}
.navigationBarBackButtonHidden(true)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button("Çıkış yap") {
print("çıkış yap")
try! Auth.auth().signOut()
UserDefaults.standard.set(false,forKey: "status")
NotificationCenter.default.post(name: NSNotification.Name("status"), object: nil)
}
}
}.navigationBarHidden(false)
NavigationView 在启动的第一个屏幕上启动,如下所示:
ZStack {
NavigationView {
VStack {
if self.status {
MapView()
} else {
VStack {
Image("AnbulanceLogo")
.resizable()
.aspectRatio(contentMode: .fit)
.padding(.horizontal, 50.0)
.edgesIgnoringSafeArea(.all)
Text("Anbulance")
.fontWeight(.heavy)
.foregroundColor(Color("AnbulanceBlue"))
.font(.system(size: 40))
.padding(.bottom, 100.0)
NavigationLink(
destination: LoginView(),
label: {
ZStack {
RoundedRectangle(cornerRadius: 5)
.frame(width: 250, height: 50, alignment: .center)
.foregroundColor(.gray)
.padding()
Text("Giriş yap")
.foregroundColor(.white)
.font(.system(size: 20))
.fontWeight(.bold)
}
})
NavigationLink(
destination: SignUpView(),
label: {
ZStack {
RoundedRectangle(cornerRadius: 5)
.frame(width: 250, height: 50, alignment: .center)
.foregroundColor(Color("AnbulanceBlue"))
Text("Kaydol")
.foregroundColor(.white)
.font(.system(size: 20))
.fontWeight(.bold)
}
})
}
}
}
.onAppear {
NotificationCenter.default.addObserver(forName: NSNotification.Name("status"), object: nil, queue: .main) { (_) in
self.status = UserDefaults.standard.value(forKey: "status") as? Bool ?? false
}
}
解决方案
推荐阅读
- vba - VBA RBG - “参数数量错误或属性参数无效”
- regex - 用空格分隔 Unicode 和 ASCII 字符
- azure - 子网 AzureFirewallSubnet 正在使用中,无法删除
- gcc - 为什么 gcc 不将 _mm256_loadu_pd 解析为单个 vmovupd?
- animation - 颤动动画在不同设备上的速度不一样快
- python - Different ways of closing files in Python
- php - 检索模型时添加自定义属性
- sql - 连接具有不同数据类型的两个表 MS ACCESS -“表达式中的类型不匹配”错误
- google-analytics - 分析电子商务:addItem 价格为零
- javascript - 使用纯Javascript输入类型文件检查图像分辨率