iOS 6/7 Deltas: Only working for subviews?
Asked Answered
H

5

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.)

Hautboy answered 1/10, 2013 at 15:50 Comment(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 rootViewDisconsolate
C
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);  
     }
   }

 }
Carrillo answered 30/1, 2014 at 8:58 Comment(0)
L
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

Langelo answered 30/1, 2014 at 8:38 Comment(0)
F
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
Finnougrian answered 24/2, 2014 at 16:39 Comment(1)
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.)Adaline
V
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);
    }
}
Viens answered 24/2, 2014 at 16:11 Comment(0)
V
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...

Varicelloid answered 4/7, 2014 at 12:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.