Xiaokun Zhao
Xiaokun Zhao

Reputation: 21

How to use transition in CAKeyframeAnimation

I want to show a few images using CAKeyframeAnimation, how can I perform transitions between images? Or how can I add CATransition to the animation? Such as: image1 eases out then image2 eases in, image2 fades out then image3 fades in, etc

Upvotes: 2

Views: 239

Answers (2)

Xiaokun Zhao
Xiaokun Zhao

Reputation: 21

One layer for one image works good. I can add animation at the begin/end of every layer to show in/out transition.

Upvotes: 0

iGatiTech
iGatiTech

Reputation: 2268

CAKeyframeAnimation :

- (void)animateImages
{
    CAKeyframeAnimation *keyframeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
    keyframeAnimation.values = self.imagesArray;

    keyframeAnimation.repeatCount = 1.0f;
    keyframeAnimation.duration = kAnimationDuration; // static const with your value

    keyframeAnimation.delegate = self;

    keyframeAnimation.removedOnCompletion = NO;
    keyframeAnimation.fillMode = kCAFillModeForwards;

    CALayer *layer = self.animationImageView.layer;

    [layer addAnimation:keyframeAnimation
                 forKey:@"girlAnimation"];
}

Upvotes: 3

Related Questions