在导航控制器上按下时视图变暗

我通过segues在NavigationController上推ViewControllers。 我有我自己的Subclassed NavigationController已经插入UIImageView索引0 – 这是我的整个应用程序的背景。

问题是,我可以看到,当新的视图控制器从右侧进入屏幕时,一开始就像在调用viewDidApear之后有一些淡淡的覆盖层正在消失。

每个视图控制器都有一个self.view.backgroundColor = [UIColor clearColor] 。 如果我改变它,一切都很好。 也许我应该以另一种方式设置应用程序的背景? 如果不是,如何避免这种黑暗的影响?

在这里,你有这个效果的屏幕截图: http : //tinypic.com/r/34j9ffs/8

这是因为iOS 7中的标准UINavigationController推动animation。当一个新的VC被压入堆栈时,它将自身覆盖在前一个VC之上,并在其下方有一个阴影。 因此,当您推送具有清晰背景的viewController时,您可以在发生转换时看到阴影。

有几个可能的解决scheme:

  • 在你的viewControllers上设置一个背景颜色(因为你的全局背景图像,可能不是你的select)。 最简单的解决scheme,但需要改变你的devise。
  • 使用新的iOS 7 API实现您自己的转换。 在这里看到一个例子和一个Big Nerd Ranch的文章。 如果你想保持你的背景图像,这真的是你的问题的“正确的”解决scheme。
  • 按照这个答案 ,添加一个UINavigationController类来添加一个更简单的“复古”push和popanimation。 这是一个更快捷的解决scheme。

我创build了一个自定义的push segue来完成这个工作:

ClearBkgPushSegue.h:

 #import <UIKit/UIKit.h> @interface ClearBkgPushSegue : UIStoryboardSegue @end 

ClearBkgPushSegue.m:

 #import "ClearBkgPushSegue.h" @implementation ClearBkgPushSegue -(void)perform { UIViewController *sourceViewController = self.sourceViewController; UIViewController *destinationViewController = self.destinationViewController; CGRect bounds = [[UIScreen mainScreen] bounds]; UIWindow *window = [[[UIApplication sharedApplication] delegate] window]; UIView *destView = destinationViewController.view; [window insertSubview:destinationViewController.view aboveSubview:sourceViewController.view]; destView.frame = CGRectMake(bounds.size.width, destView.frame.origin.y, destView.frame.size.width, destView.frame.size.height); [UIView animateWithDuration:.35 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ destView.frame = sourceViewController.view.frame; sourceViewController.view.frame = CGRectMake([UIScreen mainScreen].bounds.size.width * -0.33, 0.0, sourceViewController.view.frame.size.width, sourceViewController.view.frame.size.height); sourceViewController.view.alpha = 0; } completion:^(BOOL finished) { [sourceViewController.navigationController pushViewController:destinationViewController animated:NO]; sourceViewController.view.alpha = 1; }]; } @end 

只要select你的继续是“自定义”,select这个类,你很好去。