Objective C - How to change the contents of an Image View after performing an animation

0

Implemented an animation in Image View and would like to know how to change its image exactly after the animation ends.

Example:

- (IBAction)play:(id)sender {
    //ANIM . . .
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1]; //TEM DURAÇÃO DE 1 SEGUNDO . . .
    [UIView setAnimationBeginsFromCurrentState:TRUE];
    self.objeto.frame = CGRectMake(95, 100, 62, 62); //OBJETO É UMA IMAGE VIEW . . .
    [UIView commitAnimations];

    //NESTE CASO, MUDAR IMAGEM APÓS 1 SEGUNDO . . .
}  
    
asked by anonymous 27.07.2016 / 15:38

1 answer

1

According to Apple documentation, from iOS 4 you can use animations using blocks.

Using block animations you can perform as follows:

[UIView animateWithDuration:duração animations:^{
   //Código para realizar as animações
} completion:^(BOOL finished) {
    //Código que será chamado após as animações
}];

Now, using begin / commit, which is how you are currently doing, you can add a method that it will call after the animation completes. Remember that it is necessary to define the delegate for this method to be called at the end.

[UIView setAnimationDidStopSelector:@selector(finalizouAnimacao)];
[UIView setAnimationDelegate:self];

I recommend you take a look at the Apple documentation that talks about animations and also this SOen response that shows some arguments of why to use block animation.

Apple Documentation - Animations

Shy should I use the block-based animation rather than begin / commit animation

    
27.07.2016 / 20:31