简体   繁体   中英

NavigationView with ScrollView has unexpected velocity (or no animation) - Large Title + ScrollView - SwiftUI - iOS 14

There is an unexpected jump in the ScrollView when used in a NavigationView with large title.

The inconsistent behaviour can be seen below:

不正确的行为

The minimum code required to reproduce:

import SwiftUI

struct LeaderboardView: View {

    var body: some View {
        
        NavigationView(){
        
            ScrollView(){
                VStack(){
                        ForEach(0...50, id: \.self){ number in
                            Text("Number: \(number)").padding()
                        }
                    }.frame(maxWidth:.infinity)
                
            }.navigationBarTitle("Numbers")
            Spacer();
        }
        
    }
}

struct LeaderboardView_Previews: PreviewProvider {
    static var previews: some View {
       
            LeaderboardView()
        
    }
}

The weirder thing is that after I add vertical padding to the scroll view, the behaviour changes and it does not snap as fast as in the photo above, but it is still un-natural. This can also be reproduced in canvas while previewing.

The expected behaviour would be something like this:

活动应用

Even more on point would be the Settings page in WhatsApp.

I'm a beginner with Swift(UI). Is there a way to work around this? What am I missing?

Note: I am using XCode 12 beta 3

To have behaviour like on second gif use List

NavigationView(){
    List{
        ForEach(0...50, id: \.self){ number in
            Text("Number: \(number)").padding()
        }
    }.navigationBarTitle("Numbers")
}

This issue has been solved with the Xcode Beta 4 and iOS 14 Beta 4 update. The NavigationView() with ScrollView() can be used with no problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM