简体   繁体   中英

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.

but it seems that statusBar can't be state like "Translucent",

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 .

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. but still I can't configure statusBar from viewController. 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.

And under the simple condition like that there are one navigationController and one ViewController, both bars can make their backgrounds together (default).

Now I met the something wrong when I make tabBarController indicate to multiple navigationController by storyboard.)

According to Apple for Status bar, status bar is Transparent.(I think* always, not sure). Here is the link. 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. so this mean status bar and navigationController was originally succeeded to be transparent, my viewController is aligned (20, 0). this was root of this problem. and I found that this problem derived from applying contentInsets setting. this setting affects to even view.subviews[0] too.

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)

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.

after that, finally I could set viewController's origin to (0,0), and I made navigationBar's back being statusBar's back.

below link contains so much useful information. iOS 7 status bar back to iOS 6 default style in iPhone app?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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