2

I'm trying to make a pushViewController slide in from the left, not the right, as follows:

Page14Controller * controller = [[Page14Controller alloc] initWithNibName:@"Page14Controller" bundle:nil];

CATransition* transition = [CATransition animation];
transition.duration = 0.3;
transition.type = kCATransitionPush;
//                transition.type = kCATransitionMoveIn; 
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromLeft; 
//kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.navigationController.view.layer addAnimation:transition forKey:nil];

[self.navigationController pushViewController:controller animated:NO];

When I do this, the current controller fades to white, which looks terrible. Why does this happen? I've tried setting the background of the current view's alpha to 0.

Sofi Software LLC
  • 3,879
  • 1
  • 36
  • 34

2 Answers2

7

I figured out what was apparently causing the white flash: it was the background of the main window. Setting this to alpha=0 helps the white effect. It appears that kCATransitionPush actually fades the view being pushed off screen, and obviously if what is under that is green, then it'll fade to green. It'd be nice if it didn't also fade, but that's a different question.

Community
  • 1
  • 1
Sofi Software LLC
  • 3,879
  • 1
  • 36
  • 34
  • TY! I did have a sneaky UIView in between there that was white and that ended up causing that white background "noise". – Kalle Aug 04 '11 at 21:17
  • 4
    Hi, I have exactly the same problem and I tried to set .backgroundColor of my UIWindow with an alpha = 0 but it doesn't solve the problem. What do you do exactly ? Thanks. – delannoyk Dec 26 '12 at 10:36
0

I'd avoid messing with UIViewController's view too much.

The easier way to achieve what you want is with something like this:

UINavigationController * nc = self.navigationController;
NSArray * viewControllers = ;
NSMutableArray * newControllers = [NSMutableArray arrayWithArray:[nc viewControllers]];
[newControllers insertObject:controller atIndex:newControllers.count-1];
nc.viewControllers = newControllers;
[nc popViewControllerAnimated:YES];

Note that it replaces the top view controller with the new controller instead of just pushing it; this may not be what you want (but if you're using it to simulate page-changing, you probably don't want to perpetually push more controllers until you run out of memory).

tc.
  • 33,468
  • 5
  • 78
  • 96
  • I do want to push a new controller, though, as the new controller has a back button which will slide it off to the left, restoring the previous controller. – Sofi Software LLC Jun 23 '11 at 04:52
  • If you're going to do lots of custom stuff, then it might be worthwhile doing all the custom transitions yourself. You can just set view.frame, for instance. – tc. Jun 23 '11 at 23:26