Maria
Maria

Reputation: 765

iOS status bar and UIView

There is UIView, status bar, iOS 7 and iOS 6. With iOS 6 everything is good: my UIView (transparent, under "Tap to set destination" label) appears right below status bar. Here is the picture:

enter image description here

The problem is with iOS 7. Here:

enter image description here

I expect that UIView will be under status bar, not beneath it. I have already tried to detect iOS version and if it's 7 or upper change UIView frame programmatically. But my UI with all the constraints made in storyboard... So it did not help. What can I do to resolve this problem?

UPD: maybe I really should make design more capable for iOS7? I'll think about it, and thanks for recommendations!

Upvotes: 5

Views: 4865

Answers (4)

jose920405
jose920405

Reputation: 8057

Try many ways, I saw dozens of post. Finally this is the best solution I found.

Proper way to hide status bar on iOS, with animation and resizing root view

Upvotes: 0

yurish
yurish

Reputation: 1535

If you really really need to do this you can place the map view inside another view that will be the root view of the controller. This root view will be under the status bar in iOS 6 and take full screen in iOS 7. Set black background for the root view.

Add constrains from this root view to the map view and in viewDidLoad: check iOS version. In iOS 7 change top constrain from 0 to the status bar height (or add contain to topLayoutGuide and remove the top constrain).

But again the behavior you see is normal for iOS 7, and trying to make you view under the status bar you make your app look old-fashioned. May be it's time to reconsider you design.

Upvotes: 2

LuisEspinoza
LuisEspinoza

Reputation: 8538

In your View Controller viewDidLoad, you should add:

if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)) {
    [self setEdgesForExtendedLayout:UIRectEdgeNone];
}

Upvotes: 4

Sam B
Sam B

Reputation: 27618

In iOS 7 that's the default behavior of status bar. I guess the easiest solution will be to hide the status bar all together.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

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

}

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

Upvotes: 0

Related Questions