1

I am designing a screen using IB and in design time this is how the screen looks like: enter image description here

I am using auto layout and there are no missing constraints. This is how it lookes like when I run it using the simulator:

enter image description here

Its a sit it has no idea there is a opaque top bar there and starts layouting the views directly from the top.

does anyone has any idea why this is happening?

Thanks

Amit Raz
  • 5,370
  • 8
  • 36
  • 63
  • 1
    You need to shut translucent off. When its translucent everything technically has to start below the top bar. – logixologist Jan 12 '14 at 06:54
  • How do I do that? I have set the top bar to opaque with propmpt. should that do the trick? – Amit Raz Jan 12 '14 at 07:08
  • You just need to set the Translucent property in the code say on ViewDidLoad to no. `Translucent = NO;`. I found the `self.edgesForExtendedLayout = UIRectEdgeNone;` code to also work but the easy fix for me was the translucent property. Basically if its translucent iOS allows stuff behind it. You just need to start it around 70 pixels lower to cover for the nav bar. – logixologist Jan 13 '14 at 06:18

3 Answers3

2

The size, status bar, orientation, top bar, bottom bar are only simulated at the attributes inspector enter image description here, e.i. What u see, is NOT what u get, it's just simulate...

enter image description here

To make status bar/bottom bar/orientation etc. U must do it via code or .xib attributes inspector/size inspector.

For status bar, u can see this.

Hope it's help.

Community
  • 1
  • 1
gran33
  • 12,421
  • 9
  • 48
  • 76
0

Add the following code to viewDidLoad in you view controller:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
    self.edgesForExtendedLayout = UIRectEdgeNone;
}
Sergey Demchenko
  • 2,924
  • 1
  • 24
  • 26
0

You can achieve this by implementing a new property called edgesForExtendedLayout in iOS7 SDK. Please add the following code to achieve this,

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

You need to add the above in your -(void)viewDidLoad method.

iOS 7 brings several changes to how you layout and customize the appearance of your UI. The changes in view-controller layout, tint color, and font affect all the UIKit objects in your app. In addition, enhancements to gesture recognizer APIs give you finer grained control over gesture interactions.

Using View Controllers

In iOS 7, view controllers use full-screen layout. At the same time, iOS 7 gives you more granular control over the way a view controller lays out its views. In particular, the concept of full-screen layout has been refined to let a view controller specify the layout of each edge of its view.

The wantsFullScreenLayout view controller property is deprecated in iOS 7. If you currently specify wantsFullScreenLayout = NO, the view controller may display its content at an unexpected screen location when it runs in iOS 7.

To adjust how a view controller lays out its views, UIViewController provides the following properties:

edgesForExtendedLayout

The edgesForExtendedLayout property uses the UIRectEdge type, which specifies each of a rectangle’s four edges, in addition to specifying none and all. Use edgesForExtendedLayout to specify which edges of a view should be extended, regardless of bar translucency. By default, the value of this property is UIRectEdgeAll.

extendedLayoutIncludesOpaqueBars

If your design uses opaque bars, refine edgesForExtendedLayout by also setting the extendedLayoutIncludesOpaqueBars property to NO. (The default value of extendedLayoutIncludesOpaqueBars is NO.)

automaticallyAdjustsScrollViewInsets

If you don’t want a scroll view’s content insets to be automatically adjusted, set automaticallyAdjustsScrollViewInsets to NO. (The default value of automaticallyAdjustsScrollViewInsets is YES.)

topLayoutGuide, bottomLayoutGuide

The topLayoutGuide and bottomLayoutGuide properties indicate the location of the top or bottom bar edges in a view controller’s view. If bars should overlap the top or bottom of a view, you can use Interface Builder to position the view relative to the bar by creating constraints to the bottom of topLayoutGuide or to the top of bottomLayoutGuide. (If no bars should overlap the view, the bottom of topLayoutGuide is the same as the top of the view and the top of bottomLayoutGuide is the same as the bottom of the view.) Both properties are lazily created when requested.

Melih Büyükbayram
  • 3,100
  • 2
  • 17
  • 16