ios7 UINavigationBar在一段时间后停止在状态栏下延伸

 邻居小明 发布于 2023-02-05 11:35

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

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

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

在此输入图像描述

过了一会儿(自己闪烁):

在此输入图像描述

什么可能导致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(揭示容器)作为我的导航控制器的容器,但我不确定它是否重要.

1 个回答
  • 事实证明我正在改变clipsToBounds = YES导航控制器的导航栏(在应用程序的某个地方):

    navigationController.navigationBar.clipsToBounds = YES;

    为了UINavigationBar在状态栏下扩展其背景, 其clipsToBounds必须设置为NO(这是默认值).确保你不要嘲笑它.

    解决方案简单如:

    navigationController.navigationBar.clipsToBounds = NO;

    2023-02-05 11:39 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有