Status bar appear over my view's bounds in iOS 7 [duplicate]

ε祈祈猫儿з 提交于 2019-11-28 15:59:41
Nerrolken

iOS 7 apparently supports the Status Bar being hidden for some views but not others. To hide it for all views, do the following:

  1. Make sure Hide during application launch is still checked, to support previous OS versions.
  2. In your Info.plist file, add View controller-based status bar appearance and set it to NO.
  3. You may need to "Clean" before building, (I did), but then your app should work as before: no status bar hanging over your views!
NIKHIL

You probably need to add the following code on each view controller.

- (void)viewDidLoad
{
    [super viewDidLoad];
    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)])
    {
        [self prefersStatusBarHidden];
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
    }
    else
    {
        // iOS 6
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
    }
}

// Add this method
- (BOOL)prefersStatusBarHidden {
    return YES;
}

I have the same issue. For now I made two hacks and will decide with which I'll go:

  • You can hide status bar completely by setting UIStatusBarHidden and UIViewControllerBasedStatusBarAppearance to true.
  • In my app, I created a Top Spacing constraint with value 0, and I programmaticaly change it to 20 if I detect that the app is running on iOS 7.

How do I make Autolayout account for the status bar area?


Well, I figured it out.

In your sub-view (BRSMyListSubViewController in my case), in viewDidLoad, you need to set one of these two

self.edgesForExtendedLayout = UIRectEdgeNone;
self.automaticallyAdjustsScrollViewInsets = NO;

OR

self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = YES;

Interestingly enough, in the root view controller, these values are set to default UIRectEdgeAll, NO and YES respectively, but its tableView is NOT under navbar and footer.

I don't know why it's so illogical.

It's also strange that edgesForExtendedLayout has to be mixed with one of two other properties even though it's clearly responsible for the behavior.

Kaz Yoshikawa

If you like to show a status bar under iOS 7 with Xcode 5, just rearrange the buttons and other subviews to make enough space around the status bar. But, just wait! I like to support iOS 6 too. How do I do that?

I found documentation from Apple, and found the "Supporting Two Versions of a Standard App" title in the document.

If you are editing an XIB file, select it and click assistant editor. You will able to find the "manual, automatic..." menu around there. Then choose "preview".

Then you'll find a view layout side by side. Then you will notice that there is a popup button around the right bottom of the right pane (view); it says "iOS 7 and later". You can choose "iOS 6.1 and earlier". Woa! Now you can make adjustments for iOS 6.1 without affecting the layout of iOS 7.

If you are working on the storyboard, it is basically the same. You choose a view controller object, and click assistant editor mode, choose "preview", then "iOS7 and later"... Bluh Bluh Bluh.

I'm not sure, but only the assistant editor is capable of switching to iOS 7+/iOS 6- mode. I just found this very recently, so please point out, if there are any misunderstandings or other tricks.

DongXu

There is no need to build multi-xib. I think your problem is the "20px": the same XIB file looks great in iOS 6, but it misses 20 pixels in iOS 7.

For example, you have a view, and it's Y = 0. In iOS 6, it's next to the bottom of the status bar. In iOS 7, it appears over the status bar.

You should use Xcode 5 to open your XIB files and enable assistant editor. Follow these steps:

  1. Select file inspector, and switch "View As" to "iOS 7 and later"

  2. Select size inspector, and fill deltaY with "-20"

  3. It's done!

You just once need to check your main UIView size for iOS 7.0 & later & iOS 6.0 & lower, probably you will get idea.

From iOS 7 Apple has changed main view size = fixed It means if you add navigation bar, tabbar your view size remains same [iPhone 4s : 320 *480, iPhone 5 : 320 * 568].

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!