如何使用 Slider 为 WKInterfaceTimer 设置时间值

How to set a time value for a WKInterfaceTimer using a Slider

我正在创建一个测试应用程序以适应 WatchKit,并且想知道是否可以使用滑块来设置倒计时时间。到目前为止我有这个:

import WatchKit
import Foundation

class InterfaceController: WKInterfaceController {

@IBOutlet weak var footText: WKInterfaceLabel!
@IBOutlet weak var timerOutput: WKInterfaceTimer!

@IBAction func button() {
}
@IBAction func timeSlider(value: Float) {
var myValue = String(format: "Value is %f", value)
    func setAttributedText(attributedText: NSAttributedString?) {}

}
var testtest = "This is a test"

override func awakeWithContext(context: AnyObject?) {
    super.awakeWithContext(context)

    // Configure interface objects here.
}

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()
}

}

是否可以更改计时器的值?

如果您想更改计时器的值,可以这样设置:

  • 首先,您使用滑块更改 countTime
  • 的值
  • 之后可以设置定时器,具体取决于你的计数时间:

    timer.setDate(NSDate(timeIntervalSinceNow: countTime)) timer.start()

希望对您有所帮助!