Detecting Shakes

To detect when the user is shaking the device, you could perform some intricate math on the signal that comes from the accelerometer. However, the class UIResponder has been kind enough to implement methods that do the math for you.

/​/​ ​T​r​i​g​g​e​r​e​d​ ​w​h​e​n​ ​a​ ​s​h​a​k​e​ ​i​s​ ​d​e​t​e​c​t​e​d​
-​ ​(​v​o​i​d​)​m​o​t​i​o​n​B​e​g​a​n​:​(​U​I​E​v​e​n​t​S​u​b​t​y​p​e​)​m​o​t​i​o​n​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​w​i​t​h​E​v​e​n​t​:​(​U​I​E​v​e​n​t​ ​*​)​e​v​e​n​t​;​

/​/​ ​T​r​i​g​g​e​r​e​d​ ​w​h​e​n​ ​t​h​e​ ​s​h​a​k​e​ ​i​s​ ​c​o​m​p​l​e​t​e​
-​ ​(​v​o​i​d​)​m​o​t​i​o​n​E​n​d​e​d​:​(​U​I​E​v​e​n​t​S​u​b​t​y​p​e​)​m​o​t​i​o​n​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​w​i​t​h​E​v​e​n​t​:​(​U​I​E​v​e​n​t​ ​*​)​e​v​e​n​t​;​ /​/​ ​T​r​i​g​g​e​r​e​d​ ​w​h​e​n​ ...

Get iOS Programming: The Big Nerd Ranch Guide, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.