实例方法
high
highPriorityGesture(_:including:)
将手势附加到视图,其优先级高于视图定义的手势。
声明
func highPriorityGesture<T>(
_ gesture: T,
including mask: GestureMask = .all
) -> some View where T : Gesture
参数
gesture
附加到视图的手势。
mask
控制将此手势添加到视图如何影响视图及其子视图识别的其他手势的值。默认为
SwiftUI/GestureMask/all
。
详述
当您需要定义高优先级手势以优先于视图的现有手势时,请使用此方法。下面的示例定义了一个自定义手势,该手势将消息打印到控制台并将其附加到视图的 VStack
。在 VStack
内部,一个红色的心 Image
定义了自己的 TapGesture
处理程序,该处理程序也将消息打印到控制台,以及一个没有自定义手势处理程序的蓝色矩形。点击或单击任何视图会导致来自附加到封闭 VStack
的高优先级手势的控制台消息。
struct HighPriorityGestureExample: View {
@State private var message = "Message"
let newGesture = TapGesture().onEnded {
print("Tap on VStack.")
}
var body: some View {
VStack(spacing:25) {
Image(systemName: "heart.fill")
.resizable()
.frame(width: 75, height: 75)
.padding()
.foregroundColor(.red)
.onTapGesture {
print("Tap on image.")
}
Rectangle()
.fill(Color.blue)
}
.highPriorityGesture(newGesture)
.frame(width: 200, height: 200)
.border(Color.purple)
}
}
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相关用法
- Swift Optional hidden()用法及代码示例
- Swift Optional help(_:)用法及代码示例
- Swift Optional headerProminence(_:)用法及代码示例
- Swift Optional horizontalRadioGroupLayout()用法及代码示例
- Swift Optional hueRotation(_:)用法及代码示例
- Swift Optional symbolVariant(_:)用法及代码示例
- Swift Optional popover(isPresented:attachmentAnchor:arrowEdge:content:)用法及代码示例
- Swift Optional mask(alignment:_:)用法及代码示例
- Swift Optional listSectionSeparatorTint(_:edges:)用法及代码示例
- Swift Optional badge(_:)用法及代码示例
- Swift Optional fullScreenCover(isPresented:onDismiss:content:)用法及代码示例
- Swift Optional keyboardType(_:)用法及代码示例
- Swift Optional clipShape(_:style:)用法及代码示例
- Swift Optional preferredColorScheme(_:)用法及代码示例
- Swift Optional background(_:ignoresSafeAreaEdges:)用法及代码示例
- Swift Optional saturation(_:)用法及代码示例
- Swift Optional focusSection()用法及代码示例
- Swift Optional overlay(alignment:content:)用法及代码示例
- Swift Optional colorMultiply(_:)用法及代码示例
- Swift Optional confirmationDialog(_:isPresented:titleVisibility:presenting:actions:message:)用法及代码示例
- Swift Optional offset(_:)用法及代码示例
- Swift Optional focused(_:equals:)用法及代码示例
- Swift Optional previewDevice(_:)用法及代码示例
- Swift Optional keyboardShortcut(_:modifiers:localization:)用法及代码示例
- Swift Optional imageScale(_:)用法及代码示例
注:本文由纯净天空筛选整理自apple.com大神的英文原创作品 Optional highPriorityGesture(_:including:)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。