本文介绍了一段时间后ios7 UINavigationBar在状态栏下停止扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先 - 这不是关于导航栏重叠状态栏的问题(和许多其他人一样)。
UINavigationBar(我的导航控制器)完全按照我想要的方式对齐。

First of all - this is NOT a question about navigation bar overlapping status bar (as many others). UINavigationBar (of my navigation controller) is perfectly aligned as I want.

问题在于我的导航栏自定义背景。

背景图像(或导航栏本身)随机停止在状态栏下(在我的应用程序启动后几秒钟或当我在其上出现/关闭模态导航控制器时)。
我的自定义图片具有适合iOS的尺寸(640x128像素)。

The problem is with my navigation bar custom background.
Background image (or navigation bar itself) stops expending under status bar randomly (after few seconds after my application starts or when I present / dismiss modal navigation controllers over it).My custom image has proper dimensions for iOS (640x128px).

1。初始外观(所需 - 自定义640x128px背景在状态栏下很好地扩展):

2。过了一会儿(单独闪烁):

什么可能导致UINavigationBar背景图像的这种随机闪烁?

What could cause such random flickering of UINavigationBar background image?

I使用以下代码配置我的背景:

I use following code to configure my background:

    // 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文件中的状态栏设置:

My status bar settings in the Info.plist file:

我还在我的UIViewController子类init方法中进行了以下设置(不确定是否重要):

I have also following settings in my UIViewController subclass init method (not sure if it matters):

-(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(显示容器)作为我的导航控制器的容器,但我不确定它是否重要。

My view controllers are embedded in UINavigationController (which takes care of UINavigatioBbar positioning). I am also using ECSlidingViewController (reveal container) as a container for my navigation controllers but I am not sure if it matters.

推荐答案

事实证明我正在改变导航控制器的 clipsToBounds = YES 导航栏(应用程序中的某个位置):

It turned out I was changing clipsToBounds = YES of navigation controller's navigation bar (somewhere in the app):

navigationController.navigationBar.clipsToBounds = YES;

为了使 UINavigationBar 在状态栏
下扩展其背景,其clipsToBounds必须设置为NO (这是默认值)。
请确保您不要随意使用它。

In order for UINavigationBar to extend its background under status bar its clipsToBounds must be set to NO (which is the default).Make sure you do not mock around with it.

解决方案简单如下:

navigationController.navigationBar.clipsToBounds = NO;

这篇关于一段时间后ios7 UINavigationBar在状态栏下停止扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 17:37