Implementation of one shake
The shake function is similar to the shake function.
Method 1: analyze the accelerated counting data to determine whether the data has been shaken (complicated)
Method 2: the built-in Shake monitoring API (very simple)
This article introduces Method 2:
Steps for judging the shaking:
1) start shaking Detected
-(Void) motionBegan :( UIEventSubtype) motion withEvent :( UIEvent *) event {
// Do some processing after detection
}
2) Shake canceled or interrupted
-(Void) motionCancelled :( UIEventSubtype) motion withEvent :( UIEvent *) event {
}
3) Shake ends
-(Void) motionEnded :( UIEventSubtype) motion withEvent :( UIEvent *) event {
// Do some processing after the end
}
All the above three methods inherit the UIResponder. h In UIKit and can be directly used without the import class or the Delegate inheritance.