如何更改特定区域的工作表的 DragGesture? [英] How to change DragGesture of sheet for a specific area?

查看:20
本文介绍了如何更改特定区域的工作表的 DragGesture?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个打开工作表的按钮:

If I have a button that opens a sheet:

Button(action: { show = true }, label: { Text("Open" })
            .sheet(isPresented: $show){
                Text("Sheet view")
            }

完整的工作表是可移动的"/有一个 DragGesture.有什么方法可以停用此功能或定义此 DragGesture 的区域吗?我想把它放在工作表的上 10%.

the complete sheet is "movable"/has a DragGesture. Is there any way to deactivate this or define the area of this DragGesture? I would like to have it at the upper 10% of the sheet.

推荐答案

可能的解决方案是使用带有阻塞的 DragGesture 的工作表(所需区域的)背景.

The possible solution is to use background of sheet (of needed area) with blocked DragGesture.

这是方法的演示.使用 Xcode 12.4/iOS 14.4 测试

Here is a demo of approach. Tested with Xcode 12.4 / iOS 14.4

struct TestSheetDraggableArea: View {
    @State private var show = false
    var body: some View {
        Button(action: { show = true }, label: { Text("Open") })
            .sheet(isPresented: $show){
                SheetView()
            }
    }
}

struct SheetView: View {

    var body: some View {
        GeometryReader { gp in
            VStack(spacing: 0) {
                Color.red.overlay(Text("Draggable Area"))
                    .frame(height: gp.size.height * 0.1)
                Color.clear.overlay(
                    Text("Sheet view")      // << content here
                )
                .contentShape(Rectangle())  // makes hit testable
                .gesture(DragGesture())     // << blocks sheet dragging !!!
            }
        }.ignoresSafeArea()
    }
}

这篇关于如何更改特定区域的工作表的 DragGesture?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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