Ronald Hofmann
Ronald Hofmann

Reputation: 1430

How to achieve animations when changing image in UIImageView

I have an NSArray *pictureRefs which contains names of pictures.

These pictures are to be displayed in UIImageView _mainImage Which works fine so far.
At the moment I´m using the buttons on the left and right to do so, see picture below. The buttons have tags which correspond with pictureRefs.

The change takes place very straight without any effects.
I would like to implement coverflow like animations.

Any ideas how I could achieve this?

My code to switch image

string =  [pictureRefs objectAtIndex:tag];
UIImage  *image  = [UIImage imageNamed:string];
[_mainImage setImage:image]; //Here I would like to make animations

enter image description here

Upvotes: 2

Views: 1269

Answers (1)

Dev Patel
Dev Patel

Reputation: 290

call this method when clicked on any button

-(void)check_changeImage:(NSInteger)Value
{
    NSString *strimagename=[NSString stringWithFormat:@"dice_0%d.png",Value];//fetch image here as per you want 

 [UIView animateWithDuration:1.0 
                 animations:^{
                     imgviewDice1.image.alpha = 1.0;
                 }
                 completion:^(BOOL finished){

                     imgviewDice1.image=[UIImage imageNamed:strimagename];

                     // do something after the animation finished, 
                     // maybe releasing imageA if it's not used anymore...
                 }];

}

may be it will help.

Upvotes: 2

Related Questions