11

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?)

mm24
  • 9,280
  • 12
  • 75
  • 170

5 Answers5

22

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:

  • add a WKInterfacePicker to your Interface Controller and set the height of it to 0 in order to hide it from the user (it won't be accessible if you set 'hidden' to true)
  • 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))
    }
Thilo
  • 989
  • 1
  • 17
  • 27
6

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
    }
}
kelin
  • 11,323
  • 6
  • 67
  • 104
2

Not possible. You don't have the crown in control – it's used only automatically for scrolling etc..

Apple guidelines:

"Scrolling is the only supported Digital Crown interaction for apps, and the system automatically manages those interactions for you. Apps do not have direct access to the Digital Crown."

https://developer.apple.com/watch/human-interface-guidelines/

Apple might enable digital crown when the Apple Watch native apps are out (we will see in 2 weeks at WWDC).

Pavel Smejkal
  • 3,600
  • 6
  • 27
  • 45
  • But why Apple uses it? Will they add this capability in iOS 9? – mm24 May 28 '15 at 10:56
  • Hopefully they will :) I believe it's just because the WatchKit is restricted for now and when it is more developed, we will get access to more features.. Some of them might be available in iOS9 :) we will see in 14 days when the WWDC 2015 starts – Pavel Smejkal May 28 '15 at 10:59
  • 1
    Just a reference from Apple itself: Scrolling is the only supported Digital Crown interaction for apps, and the system automatically manages those interactions for you. Apps do not have direct access to the Digital Crown. https://developer.apple.com/watch/human-interface-guidelines/ – Alexander Gattringer May 28 '15 at 11:03
  • Yes... You can get control of crown rotation. It will provide you delta rotation value. Use that for your purpose. – Abdul Yasin May 10 '17 at 12:33
0

Like ps4 said, this is simply not possible.

As Apple states in Watch design guidelines:

"Scrolling is the only supported Digital Crown interaction for apps, and the system automatically manages those interactions for you. Apps do not have direct access to the Digital Crown."

https://developer.apple.com/watch/human-interface-guidelines/

0

Currently, this is not possible.

However, as has been announced on May 27th, Apple will introduce an SDK for native watch apps at WWDC in June. This will allow access to the digital crown.

Source: http://9to5mac.com/2015/05/27/live-blog-apple-senior-vp-of-operations-jeff-williams-interview-at-code-conference/

John
  • 8,468
  • 5
  • 36
  • 61