user1483652
user1483652

Reputation: 799

How to show buttons after an animation?

I am using this piece of code for an animation in one of my views:

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];

Now I need to state when the animation ends 2 buttons appear, 'menu' and 'replay' Do i use stopanimating or something else, please help and explain as I am a beginner, thanks for any help :)

Upvotes: 0

Views: 171

Answers (2)

Ivan Andriollo
Ivan Andriollo

Reputation: 378

You can just use an NSTimer to call another method once the animation finishes, buy using the same time interval for both the NSTimer and the animationDuration property.

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];
[NSTimer  scheduledTimerWithTimeInterval:1
                                  target:self
                                selector:@selector(showOtherButtonsAfterAnimation:)
                                userInfo:nil
                                 repeats:NO];

The NSTimer will call the method you set in selector(showOtherButtonsAfterAnimation:) of the target object(self) after the selected interval(1 second). The showOtherButtonsAfterAnimation: method needs to have an NSTimer argument even if you never use it in the method.

-(void)showOtherButtonsAfterAnimation:(NSTimer*)theTimer { .... whatever ..... }

Upvotes: 0

shabbirv
shabbirv

Reputation: 9098

Well your animation duration is 1 second so you do something like this:

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];
    [self performSelector:@selector(didFinishAnimating) withObject:nil afterDelay:1.0];


-(void) didFinishAnimating {
   //animation ended add some buttons
}

Upvotes: 1

Related Questions