Shake function: Call the system comes with the accelerator, when the device shakes, the system calculates the accelerator's acceleration value, and then tells the device whether the shaking gesture, the system will only start and end of the movement to notify you, and will not be in the whole process of the movement to report to you every time the movement. For example, if you shake the device three times quickly, you will only receive a shake event.
To implement a shake gesture, you first need to make the view controller the first responder, and note that it is not a separate control. The most appropriate time to become the first responder is to release the first responder when the view is present and when the view disappears.
1-(BOOL) Canbecomefirstresponder2 {3 returnYES;4 }5 6-(void) Viewdidappear: (BOOL) Animated7 {8 [Super viewdidappear:animated];9 [self becomefirstresponder];Ten } One A-(void) Viewdiddisappear: (BOOL) Animated - { - [Super viewdiddisappear:animated]; the [self resignfirstresponder]; -}
Then implement the Motionended method, because this method is called when the mobile phone is over.
1 -(void) motionended: (uieventsubtype) Motion withevent: (uievent *)event2{ 3 if (motion = = uieventsubtypemotionshake) {4 NSLog (@ " I am Shaker"); 5 }6 }
IOS implementation shakes a shake