NavigationVeiw中goingBack的SwiftUI问题>> [

问题描述 投票:0回答:1
我回到上一个NavigationView时遇到问题。当我想向后滑动或单击navigationView GoingBackButton时,可以执行此操作,但是当我不完全向后滑动时(例如,当我停止在屏幕的1/3中滑动时),“我的视图”冻结,并且我无法执行任何操作我的应用我不知道发生了什么,因为我真的不知道这个问题是我自己在向视图中添加新功能时是由我自己造成的,还是从一开始就出现。

这是我的故障视图代码:

import SwiftUI import CoreData struct DetailMovieView: View { let movie: Movie @Environment(\.managedObjectContext) var moc @Environment(\.presentationMode) var presentationMode @State private var showingDeleteAlert = false @State private var showingEditScreen = false var body: some View { GeometryReader { geometry in VStack { ScrollView { HStack { Text(self.movie.title ?? "Unknown Movie") .font(.largeTitle) .multilineTextAlignment(.center) Button(action: { self.showingDeleteAlert = true }) { Image(systemName: "trash") } } ZStack(alignment: .bottomTrailing) { Image(self.movie.genre ?? "Fantasy") .renderingMode(.original) .resizable() .frame(width: geometry.size.width, height: 250.0) .clipShape(Rectangle()) .overlay(Rectangle().stroke(Color.black, lineWidth: 2)) .shadow(radius: 10) Text(self.movie.genre?.uppercased() ?? "FANTASY") .font(.caption) .fontWeight(.black) .padding(8) .foregroundColor(.white) .background(Color.black.opacity(0.75)) .clipShape(Capsule()) .offset(x: -5, y: -5) } Text("Director: 2\(self.isThereDirector(director: self.movie.director ?? "Unknown director"))") .font(.caption) .foregroundColor(.secondary) Text("Year of Production: \(self.YearOfProduction(year: self.movie.productionYear))") .font(.caption) .foregroundColor(.secondary) Text(self.movie.review ?? "No review") .padding() RatingView(rating: .constant(Int(self.movie.rating))) .font(.largeTitle) Spacer() } } .alert(isPresented: self.$showingDeleteAlert) { Alert(title: Text("Delete Movie"), message: Text("Are you sure?"), primaryButton: .destructive(Text("Delete")) { self.deleteMovie() }, secondaryButton: .cancel() ) } } .navigationBarItems(trailing: Button(action: { self.showingEditScreen.toggle() }) { Image(systemName: "pencil") .imageScale(.large) .accessibility(label: Text("Edit Movie")) .padding() }) .sheet(isPresented: $showingEditScreen) { EditMovieView(movie: self.movie) } } func deleteMovie() { moc.delete(movie) presentationMode.wrappedValue.dismiss() } func YearOfProduction(year: Int16) -> String { if Int(year) != 0 { return String(year) } else { return "Unknown" } } func isThereDirector(director: String) -> String { if director != "" { return director } else { return "Unknown" } } } struct DetailMovieView_Previews: PreviewProvider { static let moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType) static var previews: some View { let movie = Movie(context: moc) movie.title = "Test Movie" movie.director = "Test director" movie.genre = "Fantasy" movie.rating = 4 movie.review = "Good movie" movie.productionYear = 2019 return NavigationView { DetailMovieView(movie: movie) } }

}

我回到上一个NavigationView时遇到问题。当我想向后滑动或单击navigationView GoingBackButton时,可以做到,但是当我不完全向后滑动时,例如当我...

swiftui freeze back-button navigationview
1个回答
0
投票
struct ContentView: View { var body: some View { NavigationView { VStack { NavigationLink(destination: DetailView()) { Text("Show Detail View") }.navigationBarTitle("Navigation") } } }
© www.soinside.com 2019 - 2024. All rights reserved.