为什么 SwiftUI 选择器在导航后重新定位表单? [英] Why is SwiftUI picker in form repositioning after navigation?

查看:16
本文介绍了为什么 SwiftUI 选择器在导航后重新定位表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击选择器后,它导航到选择视图.项目列表呈现的距离顶部太远,但在动画完成后会对齐.为什么会发生这种情况?

After clicking the picker it navigates to the select view. The item list is rendered too far from the top, but snaps up after the animation is finished. Why is this happening?

演示:https://gfycat.com/idioticdizzyazurevase

我已经创建了一个最小示例来排除导航栏标题和按钮、表单部分和其他细节:

I already created a minimal example to rule out navigation bar titles and buttons, form sections and other details:

import SwiftUI

struct NewProjectView: View {

    @State var name = ""

    var body: some View {
        NavigationView {
            Form {
                Picker("Client", selection: $name) {
                    Text("Client 1")
                    Text("Client 2")
                }
            }
        }
    }
}

struct NewProjectView_Previews: PreviewProvider {
    static var previews: some View {
        NewProjectView()
    }
}

这种情况发生在预览模式、模拟器和设备上(Xcode 11.2、模拟器中的 iOS 13.2、设备上的 13.3 beta 1).

This happens in preview mode, simulator and on device (Xcode 11.2, iOS 13.2 in simulator, 13.3 beta 1 on device).

推荐答案

在强制导航视图样式堆叠时可以解决明显错误的行为:

The obviously buggy behavior can be worked around when forcing the navigation view style to stacked:

NavigationView {
    …
}.navigationViewStyle(StackNavigationViewStyle())

这是我的问题的解决方案,但我不会将其标记为已接受的答案(目前).

This is a solution to my problem, but I won‘t mark this as accepted answer (yet).

  1. 这似乎是一个错误,即使它可能是由特殊情况触发的.
  2. 如果您需要其他导航视图样式,我的解决方案将不起作用.
  3. 此外,它不会修复 DogCoffee 在评论中提到的水平重新定位.

这篇关于为什么 SwiftUI 选择器在导航后重新定位表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆