小编pal*_*att的帖子

通过 ObservableObject 向下传递 GestureState 属性

我有一个ObservableObject带有@GestureState包装器的成员属性。在我看来,我如何才能访问该GestureState房产?

我已经尝试过在$绑定中使用点表示法来尝试公开 GestureState 但它不喜欢那样

我的应用程序状态ObservableObject

class AppState: ObservableObject {
    let objectWillChange = ObservableObjectPublisher()

    @GestureState var currentState: LongPressState = .inactive

    public enum LongPressState: String {
        case inactive = "inactive"
        case pressing = "pressing"
        case holding = "holding"
    }
}
Run Code Online (Sandbox Code Playgroud)

我的代码中对象的实现:

@ObservedObject var appState: AppState
.
.
.
let longPress = LongPressGesture(minimumDuration: minLongPressDuration)
   .sequenced(before: LongPressGesture(minimumDuration: 5))
   .updating(appState.$currentState) { value, state, transaction in
      switch value {
      case .first(true):
         state = .pressing
      case .second(true, …
Run Code Online (Sandbox Code Playgroud)

swiftui

6
推荐指数
1
解决办法
2297
查看次数

标签 统计

swiftui ×1