TapticEngine
概述
TapticEngine在iOS设备上生成触觉反馈振动。此库封装了UIImpactFeedbackGenerator、UISelectionFeedbackGenerator和UINotificationFeedbackGenerator。
演示
构建Xcode项目。
- 打开TapticEngine.xcodeproj。
- 将方案更改为
TapticEngineDemo
- 运行
用法
// Triggers an impact feedback between small, light user interface elements. (`UIImpactFeedbackStyle.light`)
TapticEngine.impact.feedback(.light)
// Triggers an impact feedback between moderately sized user interface elements. (`UIImpactFeedbackStyle.medium`)
TapticEngine.impact.feedback(.medium)
// Triggers an impact feedback between large, heavy user interface elements. (`UIImpactFeedbackStyle.heavy`)
TapticEngine.impact.feedback(.heavy)
// Triggers a selection feedback to communicate movement through a series of discrete values.
TapticEngine.selection.feedback()
// Triggers a notification feedback, indicating that a task has completed successfully. (`UINotificationFeedbackType.success`)
TapticEngine.notification.feedback(.success)
// Triggers a notification feedback, indicating that a task has produced a warning. (`UINotificationFeedbackType.warning`)
TapticEngine.notification.feedback(.warning)
// Triggers a notification feedback, indicating that a task has failed. (`UINotificationFeedbackType.error`)
TapticEngine.notification.feedback(.error)
// Prepare an impact feedback for `UIImpactFeedbackStyle.light`.
TapticEngine.impact.prepare(.light)
// Prepare a selection feedback.
TapticEngine.selection.prepare()
// Prepare a notification feedback.
TapticEngine.notification.prepare()
要求
- Swift 3.0+
- 支持iOS 9.0及以上版本(但在iOS 10或更高版本中也能工作。在iOS 9中,它将不起作用。)
安装
Carthage
TapticEngine可以通过Carthage获得。要安装它,只需在您的Cartfile中添加以下行
github "WorldDownTown/TapticEngine"
CocoaPods
TapticEngine可以通过CocoaPods获得。要安装它,只需在您的Podfile中添加以下行
pod 'TapticEngine'
手动安装
下载并将TapticEngine/Sources
文件夹拖放到您的项目中。
作者
WorldDownTown,[email protected]
许可
TapticEngine遵循MIT许可。有关更多信息,请参阅LICENSE文件。