LargeTitles UIScrollView does not support multiple observers implementing _scrollViewWillEndDraggingWithVelocity:targetContentOffset

前端 未结 5 2448
执笔经年
执笔经年 2021-02-20 09:15

I have implemented large titles in my app with the following code:

if #available(iOS 11.0, *) {
            navigationController?.navigationBar.prefersLargeTitle         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-20 09:45

    This is not a solution, but a potential thing that you need to investigate in your code. I got this same error message (UIScrollView does not support multiple observers implementing _scrollViewWillEndDraggingWithVelocity:targetContentOffset) and I noticed I was doing something incorrectly. I got this error message in a SwiftUI app using NavigationView.

    The mistake I had made was that ParentView had a Navigation View at the root. Using a NavigationLink I was moving to ChildView, which also had a NavigationView as the root. Here's what it looked like in code:

    import SwiftUI
    
    @main
    struct TestApp: App {
        var body: some Scene {
            WindowGroup {
                ParentView()
            }
        }
    }
    
    struct ParentView: View {
        var body: some View {
            NavigationView {
                List {
                    NavigationLink(destination: ChildView()) {
                        Text("Parent view")
                    }
                }
                .navigationTitle("Parent")
            }
        }
    }
    
    struct ChildView: View {
        var body: some View {
            List {
                ForEach(0 ..< 5) { _ in
                    Text("Child view")
                }
            }
            .navigationTitle("Child")
        }
    }
    

    Initially this is what ChildView looked like:

    struct ChildView: View {
        var body: some View {
            NavigationView {
                List {
                    ForEach(0 ..< 5) { _ in
                        Text("Second screen")
                    }
                }
                .navigationTitle("Second")
            }
        }
    }
    

    Notice how I was trying to push a view which itself was embedded in a NavigationView. Removing it as shown in the first snippet, took care of the error messages. You can try looking into that, maybe you are doing the same mistake just in UIKit instead of SwiftUI.

提交回复
热议问题