SwiftUI NavigationBar title ghosting problem reappears on iOS

original
2021/05/05 15:25
Reading number 282

Recently, I was writing an APP with SwiftUI, and a bug of title bar ghosting occurred occasionally, like this:

 image.png

Problem analysis:

 1. Navigate from the main page to the sub page, the sub page dynamically reads an array, and ForEach renders a list. 2. At the moment of opening the sub page, try to close the page by right sliding to close, but cancel the operation after sliding a little. 3. Slide right again to close the sub page. At this time, the navigation bar of the sub page appears on the main page, generating ghosts. 4. In the process of reproduction, slide left and cancel before rendering the list, or slide left and cancel after rendering the list, this problem will not occur

Recurrence source code:

 import SwiftUI struct ContentView: View { var body: some View { NavigationView{ NavigationLink( destination: SubView(), label: { Text ("Go to the next page") }) .navigationBarTitle(Text("Main View"), displayMode: .inline) } } } struct SubView:View { @State var message: String= @State var list: [String] = [] var body: some View{ VStack{ Text(message) ForEach(0..<list.count){ index in Text(list[index]) } } .onAppear(){ DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) { Self. message="The operation is successful, please slide left to return to the previous page" self.list = [ "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", "Test 1", ] } } .navigationBarTitle(Text("Sub View"), displayMode: .inline) .navigationBarItems( trailing: Button(action: { self.message = "Right tapped! " }, label: { Text("Right") })) } }

At present, I have consulted a lot of materials, but I have not found a reasonable solution. Welcome to exchange information with the eldest brother who has encountered this problem.

Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
zero Collection
zero fabulous
 Back to top
Top