提问人:TrMax 提问时间:10/18/2023 更新时间:10/18/2023 访问量:25
轻点“拖动手势”顶部的手势 不适用于 Apple Watch 上的 SwiftUI
Tap Gesture on top of Drag Gesture Not Working with SwiftUI on Apple Watch
问:
我正在安装了 watchOS 10.0.1 的物理 Apple Watch Series 7 上运行如下所示的视图。我正在使用 Xcode 15 构建应用程序。
当图像被拖到蓝色背景下方时,它不再起作用。当拖动图像使其不再与图像重叠时,手势似乎工作正常。Text
TapGesture
Text
import SwiftUI
struct ImageDetailView: View {
@State private var offset: CGSize = .zero
@State private var tapCount = 0
var body: some View {
ZStack(alignment: .topLeading) {
VStack {
GeometryReader { geometry in
let dragGesture = DragGesture()
.onChanged { gesture in
self.offset = CGSize(width: gesture.translation.width, height: gesture.translation.height)
}
Image(uiImage: UIImage(named: "myImage")!)
.resizable()
.scaledToFill()
.position(x: geometry.size.width / 2, y: geometry.size.height / 2)
.offset(offset)
.gesture(dragGesture)
}
}
Text("\(tapCount)")
.frame(width: 45, height: 45)
.background(Color.blue)
.contentShape(Rectangle())
.onTapGesture {
tapCount += 1
}
}
}
}
我无法在模拟器上重现该问题,只能在物理 Apple Watch 上重现该问题。
我已经尝试过 highPriorityGesture(_:including:) 和 simultaneousGesture(_:including:),
但到目前为止,没有任何组合对我有用。
即使图像已被拖到其下方,也应该有效。不知何故,如果您足够准确地点击,该手势实际上仍然有效,但它忽略了蓝色背景。TapGesture
Text
答: 暂无答案
评论