简体   繁体   English

无法在navigationBar上设置为“UIBarPositionTopAttached”

[英]can't set to “UIBarPositionTopAttached” on navigationBar

I made UIViewController which have navigationController as parent (connected in storyboard), and I want to apply picture of navigationBar for statusBar background. 我制作了UIViewController ,它将navigationController作为父级(连接在storyboard中),我想将statusBar的图片应用于statusBar背景。

but it seems that statusBar can't be state like "Translucent", 但似乎statusBar不能像“半透明”那样状态,

I tried to set 我试着设定

- (void)viewWillAppear:(BOOL)animated {    
 [self.navigationController.navigationBar setBackgroundImage:[UIImage
 imageNamed:@"barTop.png"] forBarPosition:UIBarPositionTopAttached 
 barMetrics:UIBarMetricsDefault];

 [self setNeedsStatusBarAppearanceUpdate];
 ....

}
- (UIStatusBarStyle)preferredStatusBarStyle {
  return UIStatusBarStyleLightContent;
}

in UIViewController . UIViewController

But backgrounds of navigation and status Bar have been separated. 但导航和状态栏的背景已经分开。

在此输入图像描述

I try both to make plist file as "View controller-based status bar appearance" YES and NO. 我尝试将plist文件设为“基于视图控制器的状态栏外观”是和否。 but still I can't configure statusBar from viewController. 但我仍然无法从viewController配置statusBar。 I couldn't find same problem in this bulletin board . 我在这个公告板上找不到同样的问题。

does anyone knows solution??or how to debug? 有谁知道解决方案??或如何调试?

thank you for reading. 谢谢你的阅读。

(9/3 added: I want to make backgrounds together for navigationBar and statusBar. (9/3补充说:我想为navigationBar和statusBar制作背景。

And under the simple condition like that there are one navigationController and one ViewController, both bars can make their backgrounds together (default). 在简单的条件下,有一个navigationController和一个ViewController,两个栏都可以将它们的背景组合在一起(默认)。

Now I met the something wrong when I make tabBarController indicate to multiple navigationController by storyboard.) 现在,当我使用tabBarController通过storyboard向多个navigationController指示时,我遇到了错误。)

According to Apple for Status bar, status bar is Transparent.(I think* always, not sure). 根据Apple for Status栏,状态栏是透明的。(我认为*总是,不确定)。 Here is the link. 链接在这里。 https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Bars.html https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Bars.html

在此输入图像描述

Although I found the solution this a few month ago,it took a time to align the point. 虽然我在几个月前找到了解决方案,但是花了一些时间来调整这一点。

checking my viewController structure causing problem , It found Black of the statusBar is self.window.backgroundColor. 检查我的viewController结构导致问题,发现statusBar的Black是self.window.backgroundColor。 so this mean status bar and navigationController was originally succeeded to be transparent, my viewController is aligned (20, 0). 所以这意味着状态栏和navigationController最初成功透明,我的viewController对齐(20,0)。 this was root of this problem. 这是这个问题的根源。 and I found that this problem derived from applying contentInsets setting. 我发现这个问题来源于应用contentInsets设置。 this setting affects to even view.subviews[0] too. 此设置也会影响到view.subviews [0]。

this happen when under some condition •uiViewController's view displayed via UInavigationController •edgesForExtendedLayout is active •view's first element is kind of UIScrollView or these subclass (from japanese bulletin board) 在某些情况下会发生这种情况•通过UInavigationController显示uiViewController的视图•edgesForExtendedLayout处于活动状态•视图的第一个元素是UIScrollView或这些子类(来自日本公告板)

to solute this , I made originally navigationController on the storyBoard to separate from these inset setting then I explicitly set its origin to (0,0) and I set automaticallyAdjustsScrollViewInsets = NO on my viewController. 为了解决这个问题,我在storyBoard上创建了原始的navigationController,以便从这些插入设置中分离,然后我明确地将其原点设置为(0,0),并在我的viewController上设置了selfAdjustsScrollViewInsets = NO。

after that, finally I could set viewController's origin to (0,0), and I made navigationBar's back being statusBar's back. 在那之后,我最终可以将viewController的原点设置为(0,0),然后我将navigationBar作为statusBar的后面。

below link contains so much useful information. 以下链接包含如此多的有用信息。 iOS 7 status bar back to iOS 6 default style in iPhone app? iOS 7状态栏在iPhone应用程序中恢复到iOS 6默认样式?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM