简体   繁体   English

带有 ScrollView 的 NavigationView 具有意外的速度(或没有动画) - 大标题 + ScrollView - SwiftUI - iOS 14

[英]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.在具有大标题的 NavigationView 中使用时,ScrollView 出现意外跳转。

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.这也可以在预览时在 canvas 中重现。

The expected behaviour would be something like this:预期的行为将是这样的:

活动应用

Even more on point would be the Settings page in WhatsApp.更重要的是 WhatsApp 中的设置页面。

I'm a beginner with Swift(UI).我是 Swift(UI) 的初学者。 Is there a way to work around this?有没有办法解决这个问题? What am I missing?我错过了什么?

Note: I am using XCode 12 beta 3注意:我使用的是 XCode 12 beta 3

To have behaviour like on second gif use List要具有第二个 gif 上的行为,请使用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.此问题已通过 Xcode Beta 4 和 iOS 14 Beta 4 更新解决。 The NavigationView() with ScrollView() can be used with no problems.可以毫无问题地使用带有 ScrollView() 的 NavigationView()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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