Guest User

Untitled

a guest
Jan 22nd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. class InterfaceController: WKInterfaceController {
  2.  
  3. //... existing code...
  4.  
  5. private var crownDelta = 0.0
  6.  
  7. private var count: Int = 0 {
  8. didSet {
  9. setCount(count: String(count))
  10. }
  11. }
  12.  
  13. override func awake(withContext context: Any?) {
  14. super.awake(withContext: context)
  15.  
  16. // Configure interface objects here.
  17.  
  18. crownSequencer.delegate = self
  19. }
  20.  
  21. override func willActivate() {
  22. // This method is called when watch view controller is about to be visible to user
  23. super.willActivate()
  24. crownSequencer.focus()
  25. }
  26. }
  27.  
  28. extension InterfaceController: WKCrownDelegate {
  29.  
  30. func crownDidRotate(_ crownSequencer: WKCrownSequencer?, rotationalDelta: Double) {
  31. crownDelta += rotationalDelta
  32. if crownDelta > 0.1 {
  33. count += 1
  34. crownDelta = 0.0
  35. } else if crownDelta < -0.1 {
  36. count -= 1
  37. crownDelta = 0.0
  38. }
  39. }
  40. }
Add Comment
Please, Sign In to add comment