2

I am working on updating my app to support iOS7, however one of my view is overlapping with the status bar. Please refer my image,

enter image description here

Apple recommends us to use, self.edgesForExtendedLayout = UIRectEdgeNone; to avoid fullscreen layout. however this is working when we have UIViewController within a UINavigationController and the navigationBar is visible. In my app, I didn't use the UINavigationController. can anyone help me to solve this overlapping issue on UIViewController without NavigationBar.

iPatel
  • 46,010
  • 16
  • 115
  • 137
Nandha
  • 6,746
  • 2
  • 23
  • 33

5 Answers5

5

Finally I myself found the answer. We need to offset the frame in - (void) viewDidLayoutSubviews method as like follow,

- (void) viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    if([self respondsToSelector:@selector(edgesForExtendedLayout)])
    {
        CGRect frame = self.view.frame;
        frame.origin.y = 20;
        frame.size.height = frame.size.height - 20;
        self.view.frame = frame;
    }
}

Since I am ofSetting the frame in - (void) viewDidLayoutSubviews method, user will not see the transition. If we offset the frame in -(void) viewDidload, user will see the transition. Hope this will help someone.

Nandha
  • 6,746
  • 2
  • 23
  • 33
0

Do you set wantsFullScreenLayout = YES somewhere on ViewController?

Inshiqaq
  • 41
  • 2
0

Just offset your view in viewDidLoad:

CGRect frame = self.view.frame;
frame.y = 20;
self.view.frame = frame;
StuartM
  • 6,743
  • 18
  • 84
  • 160
  • Status bar style doesn't cause this issue. The style of the status bar refers to the appearance of its content, which includes items such as time, battery charge, and Wi-Fi signal. – Nandha Sep 24 '13 at 12:55
  • See edit then. Or check here - http://stackoverflow.com/questions/18294872/ios-7-status-bar-back-to-ios-6-style/18855464#18855464 – StuartM Sep 24 '13 at 12:58
  • What does no luck mean? Does it not work, as this is the only solution to offset your frame. – StuartM Sep 24 '13 at 13:38
  • No luck means, it doesn't work. do you know any other code to offset the frame? if so post it here... – Nandha Sep 24 '13 at 13:44
  • Try changing this line frame.y += 20; instead. Also try moving to viewWillAppear this should work, step through it – StuartM Sep 24 '13 at 13:57
  • 1
    This is not working even after moving the code to viewWillAppear. So I moved this code to viewDidAppear and it changes the frame origin, however user is able to see this transition. – Nandha Sep 25 '13 at 04:32
  • you should be offsetting the frame in the viewDidload. If you do this and then log out the frame what does it log out, is the change made? Can you provide more information than no luck or doesn't work. What investigation have you done? – StuartM Sep 25 '13 at 13:07
0

I wrote a full explanation here: https://stackoverflow.com/a/18855464/1078579

The short answer is there's no way to prevent the status bar from overlapping your application on iOS 7. edgesForExtendedLayout only affects the child view controllers inside a UINavigationController or UITabBarController.

You'll need to move the contents of your app into a (0,20,320,548) container view if you want to preserve the iOS 6 style layout.

Community
  • 1
  • 1
jaredsinclair
  • 12,687
  • 5
  • 35
  • 56
-1

Add following code in ViewDidLoad

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
 {
    self.edgesForExtendedLayout = UIRectEdgeNone;
 }
Divya Bhaloidiya
  • 5,018
  • 2
  • 25
  • 45
  • 1
    It won't work when there is no navigation bar. it will work only when navigation bar is visible. – Nandha Nov 08 '13 at 13:47