I would like to use the apple watch crown to control a slider. Is this possible?
If so, how?
Apple uses it to change the colours on the UI of the watch.
EDIT: so it seems not possible at the moment (see answers below). Is important to notice that in two weeks time (Apple WWDC 2015) this could change (maybe a Watch OS for independent apps?)
The Digital Crown is is the rotating button on the side of Apple Watch. Press and hold the Digital Crown to use Siri, turn it to scroll or zoom, press it to view the Watch face or Home Screen, and double-press to open the last used app.
Apple Watch Series 4 and later provides haptic feedback for the Digital Crown, which gives people a more tactile experience as they scroll through content. By default, the system provides linear haptic detents — or taps — as people rotate the Digital Crown a specific distance.
Press the side button Press to show or hide the Dock. Press and hold to use SOS. Double-click to use Apple Pay. Press and hold to turn your watch on or off.
Since watchOS 2 beta you can use the digital crown with WKInterfacePicker!
In order to use the digital crown in combination with an WKInterfaceSlider you need to do a little workaround:
generate an array with the number of steps of your slider, example:
items = [WKPickerItem](count: numberOfSteps, repeatedValue: WKPickerItem()) picker.setItems(items)
call picker.focus()
in order to receive digital crown input
add an action to your picker that sets the slider value, example:
@IBAction func pickerChanged(value: Int) { slider.setValue(Float(value + 1)) }
All answers are outdated.
In watchOS 3 Apple introduced the WKCrownSequencer
class, that allows to track the user's interaction with the digital crown. You should implement the WKCrownDelegate
to be notified about rotation changes, then map rotation angle to the change of the value. Here is an example of how to control a WKInterfaceSlider
with help of the crown:
class SliderInterfaceController: WKInterfaceController {
@IBOutlet var slider: WKInterfaceSlider!
let minVal: Float = 0
let maxVal: Float = 10
var selectedVal: Float = 0
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// The sequencer should be focused to receive events
crownSequencer.focus()
crownSequencer.delegate = self
}
@IBAction func sliderAction(_ value: Float) {
selectedVal = value
}
}
// MARK: WKCrownDelegate
extension SliderInterfaceController: WKCrownDelegate {
func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {
// 1 divided by number of rotations required to change the value from min to max
let rotationToValRatio = 0.25 * Double(maxVal - minVal)
let newVal = selectedVal + rotationalDelta * rotationToValRatio
let trimmedNewVal = max(minVal, min(newVal, maxVal))
slider.setValue(Float(trimmedNewVal))
selectedVal = trimmedNewVal
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With