@GestureState用于跟蹤和管理與手勢相關(guān)的狀態(tài)信息瞄桨。它用于創(chuàng)建自定義手勢,并跟蹤手勢過程中的狀態(tài)變化晴圾。
使用示例
在下面的示例中,我們使用 @GestureState 跟蹤長按手勢的狀態(tài)墙牌,并根據(jù)手勢的狀態(tài)來改變視圖的顏色。
struct ContentView: View {
@GestureState private var isLongPressed = false
var body: some View {
Circle()
.fill(isLongPressed ? Color.red : Color.blue)
.frame(width: 100, height: 100)
.gesture(
LongPressGesture()
.updating($isLongPressed) { currentState, gestureState, _ in
gestureState = currentState
}
)
}
}