SwiftUI:实际可触摸区域比我指定的要大

问题描述

我正在使用 SwiftUI 为我的绘图应用程序实现一个简单的调整大小光标。

enter image description here

即使我将每个光标都变小(14x14 像素),但由于某种原因,实际的点击区域要大得多(如 40x40)。我想知道为什么会发生这种情况,并想办法消除它。

代码如下:

var body: some View {
        let center = scaled(point:model.cursorCenter)
        return ZStack {
            let rect = scaledCursor()
            Path(CGPath(rect: rect,transform: nil))
            .stroke(linewidth: 1.0)
            .foregroundColor(selectionColor)
            if !model.isDragging {
                Rectangle()
                    .frame(width:14,height:14)
                    .position(CGPoint(x: rect.maxX,y: rect.maxY))
                    .foregroundColor(selectionColor)
                    .gesture(resizeGesture(geometry: geometry,sx:nil,sy:nil))
                Rectangle()
                    .frame(width:14,height:14)
                    .position(CGPoint(x: center.x,sx:1,y: center.y))
                    .foregroundColor(selectionColor)
                    .gesture(resizeGesture(geometry: geometry,sy:1))
                Circle()
                    .frame(width:14,y: rect.minY))
                    .foregroundColor(selectionColor)
                    .gesture(rotateGesture(geometry: geometry))
            }
        }
        .transformEffect(model.cursorTransform(center: center))
        .contentShape(Rectangle())
    }

解决方法

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

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

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