Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
414 views
in Technique[技术] by (71.8m points)

iphone - How do i put a void(shake gesture) inside a IBAction(button)?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...