首先-这不是关于导航栏重叠状态栏(与其他许多栏一样)的问题。(我的导航控制器的)UINavigationBar完全按照我的要求对齐。
问题出在我的导航栏自定义背景上。
背景图片(或导航栏本身)在状态栏下随机停止消耗(在我的应用程序启动几秒钟后,或者当我在其上显示/关闭模式导航控制器时)。我的自定义图片具有适用于iOS的适当尺寸(640x128px)。
1.初步外观(希望-640x128px的自定义背景在状态栏下很好地延伸):
2.过一会儿(自身闪烁):
什么会导致UINavigationBar背景图像的这种随机闪烁?
我使用以下代码配置背景:
// Load resources for iOS 7 or later
[[CustomNavigationBar appearance] setBackgroundImage:[self imageNamed:@"bg_top_ios7.png"] forBarMetrics:UIBarMetricsDefault];
[[CustomNavigationBar appearance] setBackgroundImage:[self imageNamed:@"bg_top_ios7.png"] forBarMetrics:UIBarMetricsDefaultPrompt];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
我的状态栏设置在Info.plist文件中:
我的UIViewController子类init方法中也有以下设置(不确定是否重要):
-(id)init{
//DLog(@"BaseViewController init...");
if (self = [super init]) {
popToRoot = modal = NO;
rootIndex = 0;
indexInBottomNavigation = 0;
[Crashlytics setObjectValue:@"init" forKey:NSStringFromClass([self class])];
// iOS 7 adoptions:
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
if ([self respondsToSelector:@selector(extendedLayoutIncludesOpaqueBars)])
self.extendedLayoutIncludesOpaqueBars = YES;
if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)])
self.automaticallyAdjustsScrollViewInsets = NO;
}
return self;
}
我的视图控制器嵌入在UINavigationController中(它负责UINavigatioBbar的定位)。我还将ECSlidingViewController(显示容器)用作导航控制器的容器,但不确定是否重要。
原来,我正在更改clipsToBounds = YES
导航控制器的导航栏(在应用程序中的某个位置):
navigationController.navigationBar.clipsToBounds = YES;
为了UINavigationBar
在状态栏下扩展其背景,必须将clipsToBounds设置为NO(默认设置)。确保您不要嘲笑它。
解决方案很简单:
navigationController.navigationBar.clipsToBounds = NO;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句