HurkNburkS
HurkNburkS

Reputation: 5510

CATransaction animation fade in fade out uiviews

I have two views, jumpBarPortrait and jumpBarLandscape I would like to animate between the two so in other words I would like Portrait to fade in while landscape fades out... So far I am able to fade one in but I am not sure how to have the other fade out...

This is my code as it stands currently..

[CATransaction begin];
CATransition *animation = [CATransition animation];
animation.type = kCATransitionFade;
animation.duration = animationSpeed;

[self.view insertSubview:jumpBarContainerPortrait belowSubview:actionTabBar];

[[jumpBarContainerPortrait layer] addAnimation:animation forKey:@"Fade"];
[CATransaction commit];

any help would be greatly appreciated.

Upvotes: 0

Views: 3378

Answers (2)

danh
danh

Reputation: 62686

Have you looked at this method ...

        [UIView transitionFromView:jumpBarContainerPortrait
                            toView:jumpBarContainerLandscape
                          duration:0.5
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        completion:^(BOOL finished) {}];

Or flip the fromView/toView to transition back.

Upvotes: 3

Mil0R3
Mil0R3

Reputation: 3956

You insert the view to fade in but not remove the view fade out,try this:

[CATransaction begin];
CATransition *animation = [CATransition animation];
animation.type = kCATransitionFade;
animation.duration = animationSpeed;

[self.view insertSubview:jumpBarContainerPortrait belowSubview:actionTabBar];
[[jumpBarContainerPortrait layer] addAnimation:animation forKey:@"Fade"];

[fadeOutView removeFromSuperview];
[[fadeOutView layer] addAnimation:animation forKey:@"Fade"];

[CATransaction commit];

Upvotes: 0

Related Questions