KSTimerView

一个简单的 SwiftUI 定时器视图,支持后台运行本地通知触觉反馈

演示视频 (YouTube)

用法

使用 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)

Image

后台运行

默认情况下,将处理从后台到前台的切换。您无需执行任何操作。

本地通知

默认情况下,它是禁用的。 使用 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

贡献

  1. 如果您需要任何改进或遇到任何问题,请打开一个 issue。

谢谢! 👨🏻‍💻