Gestures: SwiftUI 的增强手势 API

Swift Platform Framework Package Manager GitHub Demo

Gestures 是一个轻量级的开源扩展,用于 SwiftUI 手势 API,它消除了 iOS 16 和 macOS 13 之前的限制 - 无法定位手势。

如何使用

此代码块演示了如何使用 Gestures 库与 SwiftUI

Rectangle()
  .onTouchGesture(count: 1) { gesture in
    print(gesture.location)
  }
  .onSwipeGesture(minimumDistance: 15.0, coordinateSpace: .local) { direction, location in
    print(direction, location)
  } onEnded: { direction, location in
    print(direction, location)
  }

有关其他使用示例,请参考示例应用程序

入门:安装

Swift Package Manager

要使用 Swift Package Manager 安装 Gestures 库,请将以下行添加到你的 Package.swift 文件中的 dependencies 数组中:

.package(url: "https://github.com/vospennikov/Gestures.git", .upToNextMinor(from: "1.0.6"))

CocoaPods

或者,你可以使用 CocoaPods 安装 Gestures。将以下行添加到你的 Podfile

pod 'SUIGestures', '1.0.6'

文档

关于 releases 和 main 的文档可在此处获取

许可

Gestures 库在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。