Seth
Seth

Reputation: 5740

UIView sliding transition fades

I've got some code inside one of my view controllers that will make sliding transition from one view to another:

-(void)transitionToNewView:(UIView*)newView
{

    UIView *superView = [self.view superview]; 
    [superView addSubview:newView]; 
    newView.frame = superView.bounds;
    [self.view removeFromSuperview]; 

    CATransition *animation = [CATransition animation]; 
    [animation setDuration:0.5]; 
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromLeft]; 
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    [[superView layer] addAnimation:animation forKey:@"keygoeshere"];
}

The sliding transition seems to work correctly, but I'm also seeing the new view fade in from a blank screen in addition to the sliding. I suspect that this is because I'm adding a new view to the super view that wasn't there before. What I'd like to do is the same thing, but without the fading in. How can I do this?

Upvotes: 0

Views: 1197

Answers (2)

Duncan C
Duncan C

Reputation: 131418

I think the kCATransitionPush transition does a fade at the same time by design. I could swear I remember reading that somewhere.

It would be pretty simple to construct a view-to-view push transition using the method transitionFromView:toView:duration:options:completion:.

Pass in UIViewAnimationOptionTransitionNone for the transition option, and then use an animation block that slides the current view off-screen while sliding the new view on-screen from the opposite direction.

Upvotes: 1

tiguero
tiguero

Reputation: 11537

I don't have a straight answer to your issue but one way I found out for handling transition between two views is to add the new view to your superview like you did, take a screenshot of each view, realize the animation and remove the two screenshots views when the transition is done. I explained more in detail what i did here and it works very well. I think it worth a try to resolve the problem you are facing. Any reason otherwise you don't use the animateWithDuration method on UIView?

Upvotes: 0

Related Questions