在swiftui中将对象移出滚动视图

问题描述

你好,滚动视图中有一个对象。执行拖动手势时,它不会退出滚动视图。我设置了 zindex 但它不起作用。如何将文本移动到图片中出现的红色区域?

struct SwiftUIView2: View {
    @State private var dragAmount = CGSize.zero

    var body: some View {
        vstack{
            
            GeometryReader { geo in
                ScrollView() {
                    ScrollViewReader { reader in
                        Text("Hello,World!")
                            .background(Color.yellow)
                            .offset(dragAmount)
                            .gesture(
                                DragGesture(minimumdistance: 0,coordinateSpace: .global)
                                    .onChanged { value in
                                        self.dragAmount = CGSize(width: value.translation.width,height: value.translation.height)
                                    }
                                    .onEnded { value in
                                        self.dragAmount = .zero
                                    }
                            )
                    }
                }
            }
            .background(Color.blue)
            .frame(width: 222,height: 100)
            .zIndex(1)
            
            Color.red
                .frame(width: 222,height: 100)
                .zIndex(0)

            
        }
    }
}

screenshot

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)