一个简单的 SwiftUI
定时器视图,支持后台运行、本地通知和触觉反馈。
使用 TimeInterval
初始化 KSTimerView,并使用 .sheet
或 .fullScreenCover
修饰符显示它,或者与 ZStack
一起使用。
.sheet(isPresented: $shouldPresentTimerView, content: {
KSTimerView(timerInterval: $timeInterval)
})
您可以使用 KSTimerView.Configuration
自定义 KSTimerView,并使用您的配置初始化 KSTimerView。
let configuration = KSTimerView.Configuration(timerBgColor: .yellow, timerRingBgColor: .red, actionButtonsBgColor: .blue, foregroundColor: .white, stepperValue: 10, enableLocalNotification: true, enableHapticFeedback: true)
KSTimerView(timerInterval: $timeInterval, configuration: configuration)
默认情况下,将处理从后台到前台的切换。您无需执行任何操作。
默认情况下,它是禁用的。 使用 KSTimerView.Configuration
中的 enableLocalNotification
启用它。
let configuration = KSTimerView.Configuration(..., enableLocalNotification: true, ...)
⚠️ 注意:您需要获得用户许可才能使用LocalNotification
。 在向用户显示计时器视图之前获取许可。
默认情况下,它是禁用的。 使用 KSTimerView.Configuration
中的 enableHapticFeedback
启用它。
let configuration = KSTimerView.Configuration(..., enableHapticFeedback: true)
KSTimerView 支持 SPM (Swift Package Manager)。 您可以使用 Xcode 集成它,File -> Swift Packages -> Add Package Dependency...
在 repo URL 中输入 https://github.com/karthironald/KSTimerView。
谢谢! 👨🏻💻