[英]Views getting darker when are pushed on navigation controller
I'm pushing ViewControllers on NavigationController by segues. 我通过segues在NavigationController上推送ViewControllers。 I have my own subclassed NavigationController which has inserted UIImageView
at index 0 - it's a background for my entire application. 我有自己的子类NavigationController,已在索引0处插入UIImageView
它是整个应用程序的背景。
The problem is that I can see that when new view controller is coming to the screen from the right side, in the beginning it's like having some light dark overlay which is disappearing when just after viewDidApear
is called. 问题是我可以看到,当新的视图控制器从右侧进入屏幕时,一开始就像是有一些浅黑的覆盖层,在调用viewDidApear
之后消失了。
Every view controller has a self.view.backgroundColor = [UIColor clearColor]
. 每个视图控制器都有一个self.view.backgroundColor = [UIColor clearColor]
。 If i change it for while, everything is fine. 如果我暂时更改它,一切都很好。 Maybe i should set background of application in another way? 也许我应该以其他方式设置应用程序背景? And if not, how to avoid this darkling effect? 如果没有,如何避免这种发黑现象?
Here you have screen capture with this effect: http://tinypic.com/r/34j9ffs/8 在这里,您将获得具有这种效果的屏幕截图: http : //tinypic.com/r/34j9ffs/8
It's because of the standard UINavigationController
push animation in iOS 7. When a new VC is pushed onto the stack, it overlays itself on top of the previous VC, with a slight shadow underneath it. 这是因为iOS 7中使用了标准的UINavigationController
推送动画。将新的VC推送到堆栈上时,它将自身覆盖在先前VC的顶部,并在其下面有一个阴影。 As such, when you push your viewControllers which have clear backgrounds, you see through to the shadow when the transition takes place. 这样,当您推送具有清晰背景的viewControllers时,过渡发生时您会看到阴影。
There are a couple of possible solutions: 有两种可能的解决方案:
UINavigationController
category to add a simpler 'retro' push and pop animation, as per this answer . 根据此答案 ,添加UINavigationController
类别以添加更简单的“复古”推送和弹出动画。 This is more of a quick and hacky solution. 这更像是一种快速而棘手的解决方案。 I created a custom push segue that should do the job: 我创建了一个应该执行此任务的自定义推送序列:
ClearBkgPushSegue.h: ClearBkgPushSegue.h:
#import <UIKit/UIKit.h>
@interface ClearBkgPushSegue : UIStoryboardSegue
@end
ClearBkgPushSegue.m: 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
Just select your segue to be "Custom" and choose this class and you're good to go. 只需选择要“自定义”的选项,然后选择该课程,您就可以开始了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.