How to apply top offset for status bar in iOS7 for

2019-02-21 23:15发布

My app is a UITabBarController based app with 3 children vc. The status bar is overlapping with my viewcontrollers. I have tried everything I have found in SO:

  1. I tried adding this to my AppDelegate:

    //Offset downwards to make room for status bar self.window.bounds = CGRectMake(0, -20, self.window.frame.size.width, self.window.frame.size.height);

It worked because it moved the entire UITabBarController down by 20. But this resulted in the tabs being cut off at the bottom by -20.

So Im thinking i just want to apply the effect to the UIViewControllers in each tab since there is not much to cut off at the bottom.

  1. So I tried adding similar code to the viewDidLoad and calling setNeedsDisplay afterwards:

    self.view.bounds = CGRectMake(0, -20, self.view.frame.size.width, self.view.frame.size.height);

But this has no effect at all, still get overlapping.

  1. I tried adding this to viewDidLoad

    self.edgesForExtendedLayout = UIRectEdgeNone;

and I also unchecked the Extend Edges Under Top Bars but it still runs into the status bar. Also tried:

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
 {
    self.edgesForExtendedLayout = UIRectEdgeNone;
 }

but no cigar.

  1. I dont have the deltas because im using AL.

  2. I dont want to HIDE my status bar because it displays open/close times so the user would find it handy to be able to see the time.

Im thinking shifting the view down a bit in each viewcontroller that needs it is the best option, but why didnt my code work for #2?

Hierarchy

(btw:not sure why code format isnt working and the numbering is off, even when i try to edit it, it seems to be working fine in the edit view but not in the pre-view or live-view)

2条回答
爷的心禁止访问
2楼-- · 2019-02-21 23:30

for iOS 7 and xcode 5 to avoid overlapping

use in

viewDidLoad method

self.edgesForExtendedLayout = UIRectEdgeNone;
self.automaticallyAdjustsScrollViewInsets = NO;
查看更多
三岁会撩人
3楼-- · 2019-02-21 23:37

Well, I have the same problem as you. I fixed it with many moves. I use ruby motion:

@window.bounds = CGRectMake(0, -20, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height - 20)
@window.frame = CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height)
....
tabBarController.view.bounds = CGRectMake(0, 20, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height - 20)

Let me know how it's going at your end.

update: attach the screenshot:enter image description here

查看更多
登录 后发表回答