Skip to content

Instantly share code, notes, and snippets.

@lalabuy948
Last active June 17, 2019 08:32
Show Gist options
  • Save lalabuy948/87c4491f066ced98162b554ab0a53d7f to your computer and use it in GitHub Desktop.
Save lalabuy948/87c4491f066ced98162b554ab0a53d7f to your computer and use it in GitHub Desktop.
Crown rotate event for WatchKit
import WatchKit
import Foundation
class InterfaceController: WKInterfaceController, WKCrownDelegate {
@IBOutlet var skInterface: WKInterfaceSKScene!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// start listening to crown
crownSequencer.delegate = self
crownSequencer.focus()
...
}
func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {
// convert crown rotation to CGFloat
let step = NSNumber.init(value: rotationalDelta * 20.0).floatValue
let cgStep = CGFloat(step)
// log whats happened
print("Crown: \(cgStep)")
gameScene.doSomething(amountX: cgStep, amountY: 0)
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment