I know how to detect shake gesture
. It can be detect by following procedure :
Open your 'AppDelegate.m
' and add the code below to the application:didFinishLaunchingWithOptions:
method.
You must add it before the 'return YES
'.
[application setApplicationSupportsShakeToEdit:YES];
Now open your 'viewController.m
' file of the controller
in which you want to use the shake gesture
. Edit the viewDidAppear:
and viewDidDisappear:
methods.
Add the following code:
- (void)viewDidAppear:(BOOL)animated {
[self becomeFirstResponder];
}
- (void)viewDidDisappear:(BOOL)animated {
[self becomeFirstResponder];
}
After that you should add the methods in the code below:
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
// Do your thing after shaking device
}
But I wanted to know logic how shake works.
How it can be detected? Does it use CoreMotion
(accelerometer
, magnetometer
, and the gyroscope
) for detecting?
If anyone knows please share.