I know, shake it. The following 2 options are available:
First, the direct use of the system to bring the Motionbegan method
-(void) Motionbegan: (uieventsubtype) Motion withevent: (uievent *) event
If the program does not respond to this method, try adding the following method:
-(BOOL) Canbecomefirstresponder
{
return YES;
}
If not, it is recommended to use the second method.
Second, the method of motionbegan+ notice
1. Write Motionbegan method in Appdelegate
-(void) Motionbegan: (uieventsubtype) Motion withevent: (uievent *) event
{
[[nsnotificationcenterdefaultcenter]postnotificationname:@ "Shake" object:self];
}
2. Add a notification to the page where you want to receive notifications
[[Nsnotificationcenterdefaultcenter]addobserver:selfselector: @selector (shakeaction) name:@ "Shake" object:nil];
Write it in the viewdidload.
The shakeaction here is to shake a shake need to call the method, their own changes, the notification name corresponding to the good, can be freely modified.
Three. Other ways to add a shake
/** Shake the end (need to be processed here after the end of the code) */
-(void) motionended: (uieventsubtype) Motion withevent: (uievent *) event
{
Not shaking a motion event
if (Motion! = Uieventsubtypemotionshake) return;
NSLog (@ "motionended");
}
/** Shake to cancel (interrupted, such as sudden call) */
-(void) motioncancelled: (uieventsubtype) Motion withevent: (uievent *) event
{
NSLog (@ "motioncancelled");
}
IOS shaking a Shake event