背景中的CATransition白色闪光?

时间:2011-06-21 23:57:26

标签: iphone ios uinavigationcontroller pushviewcontroller catransition

我正在尝试从左侧而不是右侧滑入pushViewController,如下所示:

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];

当我这样做时,当前控制器逐渐变白,看起来很糟糕。为什么会这样?我已经尝试将当前视图的alpha背景设置为0。

2 个答案:

答案 0 :(得分:7)

我想出了显然导致白色闪光的原因:它是主窗口的背景。将此设置为alpha = 0有助于白色效果。它appears that kCATransitionPush actually fades the view being pushed off screen,显然如果它是绿色的,那么它将渐渐变为绿色。如果它不会褪色会很好,但这是一个不同的问题。

答案 1 :(得分:0)

我会避免过多地使用UIViewController的视图。

实现目标的更简单方法是使用以下内容:

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];

请注意,使用新控制器替换顶视图控制器而不是仅推送它;这可能不是您想要的(但如果您使用它来模拟页面更改,您可能不希望永久地推送更多控制器,直到内存不足为止。)