0

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?

Seth
  • 5,596
  • 8
  • 42
  • 56
  • Core animation defaults to a fade when an error occurs or an invalid parameter is passed to the animation object. – CodaFi Jun 06 '12 at 21:20

2 Answers2

1

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.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
0

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?

Community
  • 1
  • 1
tiguero
  • 11,477
  • 5
  • 43
  • 61