Skip to main content
updated code snippet for current Swift version
Source Link
Ric Santos
  • 16.7k
  • 7
  • 56
  • 81

Super easy to implement:

  1. Let iOS know which view controller is the first in the responder chain:

    override func viewDidLoad() { super.viewDidLoad() self.becomeFirstResponder() }
    override func canBecomeFirstResponder() -> Bool { return true }

  2. Handle the event in some fashion:

    override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent!?) { if(event.subtype == UIEventSubtype.MotionShake) { print("You shook me, now what") } }

Super easy to implement:

  1. Let iOS know which view controller is the first in the responder chain:

    override func viewDidLoad() { super.viewDidLoad() self.becomeFirstResponder() }
    override func canBecomeFirstResponder() -> Bool { return true }

  2. Handle the event in some fashion:

    override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent!) { if(event.subtype == UIEventSubtype.MotionShake) { print("You shook me, now what") } }

Super easy to implement:

  1. Let iOS know which view controller is the first in the responder chain:

    override func viewDidLoad() { super.viewDidLoad() self.becomeFirstResponder() }
    override func canBecomeFirstResponder() -> Bool { return true }

  2. Handle the event in some fashion:

    override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent?) { if(event.subtype == UIEventSubtype.MotionShake) { print("You shook me, now what") } }

deleted 2 characters in body
Source Link
Tunaki
  • 138.2k
  • 46
  • 370
  • 443

Super easy to implement:

  1. Let iOS know which view controller is the first in the responder chain:

    override func viewDidLoad() { override func viewDidLoad() { super.viewDidLoad() self.becomeFirstResponder() } override func canBecomeFirstResponder() -> Bool { return true }super.viewDidLoad() self.becomeFirstResponder() }
    override func canBecomeFirstResponder() -> Bool { return true }

  2. Handle the event in some fashion:

    override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent!) { if(event.subtype == UIEventSubtype.MotionShake) { print("You shook me, now what") } }

Super easy to implement:

  1. Let iOS know which view controller is the first in the responder chain: override func viewDidLoad() { super.viewDidLoad() self.becomeFirstResponder() } override func canBecomeFirstResponder() -> Bool { return true }

  2. Handle the event in some fashion:

    override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent!) { if(event.subtype == UIEventSubtype.MotionShake) { print("You shook me, now what") } }

Super easy to implement:

  1. Let iOS know which view controller is the first in the responder chain:

    override func viewDidLoad() { super.viewDidLoad() self.becomeFirstResponder() }
    override func canBecomeFirstResponder() -> Bool { return true }

  2. Handle the event in some fashion:

    override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent!) { if(event.subtype == UIEventSubtype.MotionShake) { print("You shook me, now what") } }

Source Link
Ryan Dines
  • 1.1k
  • 11
  • 18

Super easy to implement:

  1. Let iOS know which view controller is the first in the responder chain: override func viewDidLoad() { super.viewDidLoad() self.becomeFirstResponder() } override func canBecomeFirstResponder() -> Bool { return true }

  2. Handle the event in some fashion:

    override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent!) { if(event.subtype == UIEventSubtype.MotionShake) { print("You shook me, now what") } }