CATransition white flash in background?

无人久伴 提交于 2019-12-11 04:01:56

问题


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.


回答1:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/6433385/catransition-white-flash-in-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!