Padin215
Padin215

Reputation: 7484

transition from A image to B image with animation

I have an UIImageView of an white color arrow image. I am animating it to rotate 90 degree's. I also want that UIImageView to change to a black color arrow image as it rotates.

The only solution I can think of is to stack the two images on top of each other, animate both when ever it rotates and change the white color arrow image's alpha (so it fades in and out).

Is there a simpler way to obtain this effect?

Is there a build in transition effect to fade one image out and another image in?

Upvotes: 0

Views: 255

Answers (1)

NJones
NJones

Reputation: 27147

You seem to have a good grasp of what to do. Probably the easiest repeatable way to do this is to create a UIView subclass and add both of your arrows to it. Then add a couple of functions like these.

-(void)rotate90{
    blackArrow.alpha = 0;
    [self bringSubviewToFront:blackArrow];
    [UIView animateWithDuration:1 animations:^{
        blackArrow.alpha = 1;
        blackArrow.transform = CGAffineTransformMakeRotation(M_PI_2);
        whiteArrow.transform = CGAffineTransformMakeRotation(M_PI_2);
    }];
}
-(void)rotate0{
    whiteArrow.alpha = 0;
    [self bringSubviewToFront:whiteArrow];
    [UIView animateWithDuration:1 animations:^{
        whiteArrow.alpha = 1;
        blackArrow.transform = CGAffineTransformMakeRotation(0);
        whiteArrow.transform = CGAffineTransformMakeRotation(0);
    }];
}

Upvotes: 1

Related Questions