I’m creating an app where when the user shake’s the iPhone an animation plays, I’m using this code:
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.subtype == UIEventSubtypeMotionShake)
{
animation...
}
The thing is the code above reacts as soon as the user shake’s the iPhone, just once. I need the user to shake it for up and down, as if they were shaking a bottle, for a few seconds and then the animation plays, also whilst they shake a mp3 file must play and when the animation plays a sound must play, please help, I am a total beginner so explain answers, thank you 🙂
Declare
int numOfShakes;in your .h file and increment it everytime the user shakes their phone and once they reach a certain amount of shakes then call the animation code