實例方法
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:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。