1

I am using the following code to switch between views with CATransition.

CATransition *applicationLoadViewIn = [CATransition animation];

    [applicationLoadViewIn setDuration:20];

    [applicationLoadViewIn setType:kCATransitionPush];

    [applicationLoadViewIn setSubtype:kCATransitionFromTop];

    [applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];

    ViewToSwitchTo *myviewcontroller = [[ViewToSwitchTo alloc] init];

    [self.view.layer addAnimation:applicationLoadViewIn forKey:kCATransitionPush];

    [self.view addSubview:myviewcontroller.view];

It functions mostly how I want it to. It pushes from the top like it should, however it for some reason acts strangely. First, the view I am switching to starts coming in from the bottom like it should, but for some reason, the view that I am switching FROM appears over the top of it with low opacity, so you see both of them. However, you also see the view that is coming in, shifted maybe 100 pixels upwards, on top of itself and the other view, once again with low opacity. Just before the halfway point of the the transition, everything works fine, you only see the view that is coming in and the view going out, doing what they should be doing. But slightly after the halfway point, the view I am switching to appears in its final destination, under the view I am switching from, and the view I am switching from has been reduced in opacity.

What is going on here?

Regan
  • 1,487
  • 2
  • 28
  • 43
  • I have no idea what's going on here, but if you haven't watched the 2010 WWDC sessions 424 & 425 _Core Animation in Practice_ (Parts 1 & 2), you should. They may or may not shed light on this particular problem, but they're chock full of fantastic CA-related advice at an extremely detailed level. – mharper Dec 23 '10 at 21:12
  • I think, this is just the way it works. see [this question](http://stackoverflow.com/questions/2687363) – murat Dec 23 '10 at 21:26

2 Answers2

0

I really not understand what you want but hope this code will help to implement ,if not then tell more about you CATransition

-(void) startAnimation {
    fullImageView.alpha = 0.50;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationRepeatCount:1];
    [UIView setAnimationRepeatAutoreverses:NO];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(pulseAnimationDidStop:finished:context:)];
    fullImageView.alpha = 1.0;
    [UIView commitAnimations];
}

- (void)pulseAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    if(hasFocus) {
        [self startAnimation];
    } else {
        fullImageView.alpha = 1.0;
    }
}

-(void) setHasFocus:(BOOL)_hasFocus {
    hasFocus = _hasFocus;
    if(hasFocus) {
        [self startAnimation];
    }
}
Justin Spahr-Summers
  • 16,893
  • 2
  • 61
  • 79
GhostRider
  • 1,197
  • 10
  • 19
0

You can use this way as well

CATransition *applicationLoadViewIn = [CATransition animation];
    [applicationLoadViewIn setDuration:1.5];
    [applicationLoadViewIn setType:kCATransitionPush];
    [applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
    //[applicationLoadViewIn setRepeatCount:114];

    productVC=[[PoductViewController alloc]initWithNibName:@"PoductViewController" bundle:[NSBundle mainBundle]];

    [[productVC.view layer] addAnimation:applicationLoadViewIn forKey:kCATransitionPush];
    [self.view addSubview:productVC.view];

But I suggest you to use Navigation Controller in place of

[self.view addSubview:productVC.view];

just use

[self.navigationController pushViewController:productVC animated:YES];

If you use this, there will be no background view, you will see white screen of the present view. But if you add subview, then you need to manually remove subview.

Pang
  • 9,564
  • 146
  • 81
  • 122
Sabby
  • 2,586
  • 2
  • 27
  • 41