问题
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
回答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.
来源:https://stackoverflow.com/questions/11264989/how-do-i-put-a-voidshake-gesture-inside-a-ibactionbutton