View got hidden below UINavigationBar iOS 7

2020-01-29 03:48发布

Earlier, I was using iOS 6.1 for my project. Recently I have switched to iOS 7. For, a lot of changes I knew, I updated my code.. But I have observed a strange behavior. My view on every screen gets hidden below navigation bar. Repositioning view solves the problem for iOS7, but creates problems for older iOS versions.

Can anyone explain me, what is the reason and why does it happen?? What has been changed in iOS 7 that's causing this problem??

Any help would be appreciated..

9条回答
我只想做你的唯一
2楼-- · 2020-01-29 04:23

Look up this key: UIViewControllerBasedStatusBarAppearance.

It's used in your app's info PLIST file and will come up as:

View controller-based status bar appearance

This will allow you to control the status bar's appearance. There's a bunch of API changes for status bars, go have a look in the documentation for new UIViewController methods such as

- (void)prefersStatusBarHidden;

查看更多
再贱就再见
3楼-- · 2020-01-29 04:25

If you do not need translucent navigation bar in your app you can fix this on iOS7 and iOS6 without code changes.

In storyboard select your navigation controller and then open "Attributes Inspector". Then under "Simulated Metrics" set "Top Bar" to some value but not to "translucent":

Setting Top Bar style

Now your views on iOS6 and iOS7 will have the same positioning as before.

查看更多
Anthone
4楼-- · 2020-01-29 04:26

Point #7 on this list does the trick. You still have to wrap it in iOS 7-checking code like @null's answer:

float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (systemVersion >= 7.0) {
    viewController.edgesForExtendedLayout = UIRectEdgeNone;
}

The whole article is useful to those transitioning to iOS 7.

查看更多
爷、活的狠高调
5楼-- · 2020-01-29 04:26

Use this property for your VC, in-order to avoid overlap of ur statusbar with your VC Swift :

self.edgesForExtendedLayout = []

Objective C

self.edgesForExtendedLayout = UIRectEdgeNone;
查看更多
别忘想泡老子
6楼-- · 2020-01-29 04:29

For me the best way for transparent Navigation Bar is to change the shadowImage and backgroundImage of the bar.

navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.backgroundColor = nil
navigationController?.navigationBar.setBackgroundImage(UIImage(named: "navBarBackground")?.resizableImage(withCapInsets: .zero, resizingMode: .stretch), for: .default)  
navigationController?.navigationBar.shadowImage = UIImage()
查看更多
可以哭但决不认输i
7楼-- · 2020-01-29 04:31

You can stop your views going under the navigation bar, in your viewController:

self.edgesForExtendedLayout = UIRectEdgeNone;
查看更多
登录 后发表回答