9

I designed my iPhone app for iOS 5 and 6. Now I want it to support iOS 7 but the two older versions as well. Like many developers I have been struggling with the status bar overlapping my views and I understand that there is no way to preserve the old status bar style in iOS 7.

Yet many posts on Stackoverflow suggest to use the iOS 6/7 Deltas which can be set in Xcode with the new SDK:

iOS 6/7 Deltas in Xcode

I have tried that but I have found that nothing happens when I apply these values to the root view of a view controller. These Deltas only have an effect on all the subviews contained within the root view.

Why do the Deltas not work for the root view? Is there a way to make it work? (I do not want to add Deltas to all my UI elements in all my view controllers.)

Community
  • 1
  • 1
Mischa
  • 12,670
  • 7
  • 51
  • 94
  • 1
    It is specification of ios7 to use full screen, so, root view will remain always full screen. So, you have to put deltas to all the components. or you can do this- add one new view having delta and put all other components in it and put thet view in your rootView – Mehul Thakkar Oct 09 '13 at 09:45

5 Answers5

2

I have found this work around which works fine for me.

 -(void)viewWillLayoutSubviews
{
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) 
   {
    // Load resources for iOS 6.1 or earlier
    if(IS_IPhone5)
    {
        self.view.frame = CGRectMake(0.0, -64.0, 320.0, 568.0);
    }
    else
    {
      self.view.frame = CGRectMake(0.0, -64.0, 320.0, 480.0);  
     }
   }

 }
bhavya kothari
  • 7,471
  • 4
  • 25
  • 53
1

From you question What I think is you seems tired of setting delta values for individual subviews. But its very easy I think. Just select all the subviews:

enter image description here

and you can add same delta values for all your subviews from size inspector at one shot...as simple as that!!

enter image description here

Ajay
  • 1,568
  • 19
  • 35
1

Let me help you, actually its quiet simple. You need to follow steps given below:

Set view As iOS 7 for target xib in File Inspector.

1.Put all your views in a container view which will have frame (0,20, rootViewWidth, rootViewHeight), using Interface Builder. Note: No need to set delta for any of views inside container view. Delta for container view will be: delta-Y =-20, delta-height=20 else are zero

2.Put one more view(name it as statusBarBackgroudView) of frame (0,0,rootViewWidth,20) in xib. Deltas for statusBarBackgroudView will be: delta-Y = -20 else are zero.

Give desired bg color to statusBarBackgroudView which will be shown below status bar in iOS 7 and in iOS 6 it will simply shift to Y = -20, so will not be visible.

View hierarchy in XIB should look like below:

Root View
 -Container View
   -your subviews
 -Status Bar Background View
dev gr
  • 2,139
  • 1
  • 18
  • 33
  • I'm surprised this answer didn't get more up-votes. Nice clean explanation and using the Xcode features the way they were intended, without the need for extra IF statements in the code. (Thanks also for the "View as iOS7" tip - that's the part I was missing.) – Erik van der Neut Jul 29 '14 at 08:55
0

This code segment solved the problem for me. I have put it into a BaseViewController, which is a superclass for all the UIViewController's in the project. I think it is more feasible to add this simple code instead of modifying deltas on each xib file. Derived from bhavya kothari's answer:

- (void)viewWillLayoutSubviews{

    [self fixStatusBarOffsetIfiOS6];
    [super viewWillLayoutSubviews];
}

- (void)fixStatusBarOffsetIfiOS6{

    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1){
        self.view.frame = CGRectMake(0.0, -20.0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) + 20);
    }
}
Yunus Nedim Mehel
  • 11,371
  • 4
  • 47
  • 54
0

if (IS_Ios6) {

    if (IS_IPHONE_4) {
        self.view.frame = CGRectMake(0, 0, 320, 480);
    } else if (IS_IPAD){
        self.view.frame = CGRectMake(0, 0, 768, 1024);
    }
    self.wantsFullScreenLayout = YES;
}

put this code in viewDidLoad...

JATIN
  • 31
  • 1