Structure

GestureState

A property wrapper type that updates a property while the user performs a gesture and resets the property back to its initial state when the gesture ends. あるプロパティラッパー型、それは、あるプロパティをユーザがジェスチャを実行する間に更新します、そしてそのプロパティをジェスチャが終わる時にそれの初期状態へと再設定します。

Declaration 宣言

@propertyWrapper @frozen struct GestureState<Value>

Overview 概要

Declare a property as @GestureState, pass as a binding to it as a parameter to a gesture’s updating(_:body:) callback, and receive updates to it. A property that’s declared as @GestureState implicitly resets when the gesture becomes inactive, making it suitable for tracking transient state.

Add a long-press gesture to a Circle, and update the interface during the gesture by declaring a property as @GestureState:


struct SimpleLongPressGestureView: View {
    @GestureState var isDetectingLongPress = false


    var longPress: some Gesture {
        LongPressGesture(minimumDuration: 3)
            .updating($isDetectingLongPress) { currentState, gestureState, transaction in
                gestureState = currentState
            }
    }


    var body: some View {
        Circle()
            .fill(self.isDetectingLongPress ? Color.red : Color.green)
            .frame(width: 100, height: 100, alignment: .center)
            .gesture(longPress)
    }
}

Topics 話題

Creating a Gesture State ジェスチャ状態を作成する

Getting the State

Default Implementations 省略時実装

Relationships 関係

Conforms To 次に準拠

See Also 参照

Dynamic View Properties 動的ビュープロパティ