如何解决我正在尝试使用数字表冠来跟踪运动
我正在尝试创建一个程序,通过跟踪数字表冠的旋转来启动和停止秒表,但我不确定如何在实现中使用表冠方法。
我是 swift 的菜鸟,所以我不明白如何跟踪旋转并将其用作启动和停止手表的条件。
我的目标是在旋转小于 0 或大于 0 时启动手表,具体取决于用户旋转表冠的方式,然后将数字重置为 0。
然后我想这样做,如果时钟的状态为真(因此它正在运行)并且表冠旋转大于或小于 0,则停止计时器。
我到目前为止编写的代码适用于当您按下开始按钮时,但我正在尝试更改它,以便在您旋转数字表冠时它会激活计时器。 这是我到目前为止所做的代码。
import WatchKit
import Foundation
class InterfaceController: WKInterfaceController {
@IBOutlet weak var time: WKInterfaceTimer!
@IBOutlet weak var sbutton: WKInterfaceButton!
var timeIsStarted = false
var startTime = Date()
var elapsedTime : TimeInterval = 0.0
private var crownValue = 0.0
override func awake(withContext context: Any?) {
// Configure interface objects here.
super.awake(withContext: context)
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
// struct DigitalCrown: View {
// @State private var crownValue = 0.0
//
// var body: some View {
// Text("Received Value:\(crownValue,specifier: "%.1f")")
// .focusable()
// .digitalCrownRotation($crownValue)
// }
// }
@IBAction func stButton() {
timeIsStarted = !timeIsStarted
if timeIsStarted {
startTime = Date()
sbutton.setTitle("STOP")
time .setDate(Date(timeIntervalSinceNow: elapsedTime))
time.start()
}else{
let stoppedTime = Date()
elapsedTime -= stoppedTime.timeIntervalSince(startTime)
sbutton.setTitle("START")
time.stop()
}
}
// if(crownValue != 0.0) {
// timeIsStarted = !timeIsStarted //change timeisstarted to true
// crownValue = 0.0
// }
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。