0

I am creating an app and I have bumped into a problem. My app has a play button, once the user presses it a animation plays and finishes. I have created the above in code which I will display below, but I need some help. When the player press's play, it should display a label saying shake to start, and when the user shake's the iPhone the label will disappear and the animation will start. I am not able to put the animation code inside the IBAction code. Please help :)

-(IBAction)startanimation { 



animation.animationImages= [NSArray arrayWithObjects:
                                [UIImage imageNamed:@"Frame0.png"],
                                [UIImage imageNamed:@"Frame1.png"],
                                [UIImage imageNamed:@"Frame2.png"],
                                [UIImage imageNamed:@"Frame3.png"],
                                [UIImage imageNamed:@"Frame4.png"],
                                [UIImage imageNamed:@"Frame5.png"],
                                [UIImage imageNamed:@"Frame6.png"],
                                [UIImage imageNamed:@"Frame7.png"],
                                [UIImage imageNamed:@"Frame8.png"],
                                [UIImage imageNamed:@"Frame9.png"],
                                [UIImage imageNamed:@"Frame10.png"],
                                [UIImage imageNamed:@"Frame11.png"],
                                [UIImage imageNamed:@"Frame12.png"],
                                [UIImage imageNamed:@"Frame13.png"],
                                [UIImage imageNamed:@"Frame14.png"], 
                                nil];

    [animation setAnimationRepeatCount:1];
    animation.animationDuration = 1;
    [animation startAnimating];


    button.hidden = 1;
    animation.hidden = 0;
    Menu.hidden = 0;
    replay.hidden = 0;



}

I am a beginner at coding so please explain any answers :)

Thanks

Stevenp
  • 3
  • 3

1 Answers1

1

In your IBAction set a BOOL named something like "readyToShake" to TRUE. Then in your Shake listener check for if "readyToShake" is TRUE, if it is, start the animation. If it is FALSE, ignore the shake gesture.

WhoaItsAFactorial
  • 3,538
  • 4
  • 28
  • 45
  • Thank you, I am quite new to coding could you explain who to do the above a bit more, thanks for such a quick reply :) – Stevenp Jun 29 '12 at 15:54
  • Check out the documentation for examples of how to capture shake gestures. http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MotionEvents/MotionEvents.html – WhoaItsAFactorial Jun 29 '12 at 16:37
  • Hi thank you again, but I am so confused on how to set a BOOL and everything else, but I really need some help creating the code, please help me and point me how to do this code. What do you mean by shake listen??? by the way this is the code I am looking to put: – Stevenp Jun 29 '12 at 17:07
  • - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (event.subtype == UIEventSubtypeMotionShake) – Stevenp Jun 29 '12 at 17:07