ScrollView 打破 .sheet 表示 [英] ScrollView breaks .sheet representation

查看:14
本文介绍了ScrollView 打破 .sheet 表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 ScrollView 中嵌套在多个视图中的工作表表示工作.

I am trying to get a sheet representation work nested in multiple views inside a ScrollView.

如果没有 ScrollView.sheet 修饰符可以正常工作,但是当我将所有内容都包裹在滚动视图中时,修饰符只会触发一次.所以在第一次点击时,工作表看起来很好,但在关闭它后我无法再次触发它.我不确定这是 SwiftUI 本身的错误还是我在这里做的事情.

Without the ScrollView the .sheet modifier works fine, but when I wrap everything inside the scroll view the modifier, triggers only once. So on the first tap the sheet appears fine, but after dismissing it I can not trigger it again. I am unsure whether this is a bug in SwiftUI itself or if I am doing something here.

注意:如果我将 .sheet 修饰符添加到 ScrollView 本身,则一切正常.但是对于我的用例,.sheet 修饰符被深度嵌套在 ScrollView 内的自定义视图中.

Note: If I add the .sheet modifier to the ScrollView itself, everything is working. But for my use case the .sheet modifier is added deeply nested inside a custom view inside the ScrollView.

我使用的是 Xcode Beta 5

I am using the Xcode Beta 5

没有 ScrollView - 有效

struct SheetWorks: View {
    @State var showSheet = false

    var strings = [
      "Hello", "World", "!"
    ]

    var body: some View {
        HStack {
            ForEach(strings) { string in
                Button(action: {self.showSheet.toggle()}) {
                    Text(string)
                }
                .sheet(isPresented: self.$showSheet) {
                    Text("Here is the sheet")
                }
            }
        }
        .padding()
    }
}

使用 ScrollView - 不起作用

struct SheetDoesntWork: View {
    @State var showSheet = false

    var strings = [
      "Hello", "World", "!"
    ]

    var body: some View {
        ScrollView(.horizontal) {
            HStack {
                ForEach(strings) { string in
                    Button(action: {self.showSheet.toggle()}) {
                        Text(string)
                    }
                    .sheet(isPresented: self.$showSheet) {
                        Text("Here is the sheet")
                    }
                }
            }
            .padding()
        }
    }
}

也许有人经历过类似的事情,或者可以为我指明正确的方向.我真的很感激任何帮助.

Maybe someone has experienced something similar or can point me in the right direction. I really appreciate any help.

这个问题在 Beta 6 中仍然存在

推荐答案

Xcode 11.1 GM Seed 开始,我可以批准 .sheet 修饰符现在可以在<代码>滚动视图.此外,多行 Text 现在也正确呈现.

As of Xcode 11.1 GM Seed I can approve that the .sheet modifier now works correctly inside the ScrollView. Furthermore also a multiline Text is now correctly rendered.

这篇关于ScrollView 打破 .sheet 表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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