186down votefavorite 122 |
I recently downloaded Xcode 5 DP to test my apps in iOS 7. The first thing I noticed and confirmed is that my view's bounds is not always resized to account for the status bar and navigation bar. In
This results in my content appearing below the navigation bar and status bar. I know I could account for the height myself by getting the main screen's height, subtracting the status bar's height and navigation bar's height, but that seems like unnecessary extra work. Has anyone else experienced this issue? UPDATE: I've found a solution for this specific problem. Set the navigation bar's translucent property to NO:
This will fix the view from being framed underneath the navigation bar and status bar. However, I have not found a fix for the case when you want the navigation bar to be translucent. For instance, viewing a photo full screen, I wish to have the navigation bar translucent, and the view to be framed underneath it. That works, but when I toggle showing/hiding the navigation bar, I've experienced even stranger results. The first subview (a UIScrollView) gets its bounds y origin changed every time.
|
||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||
start a bounty |
protected by 0x7fffffff Sep 13 at 12:17
This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.
11 Answers
up vote192down voteaccepted |
You can achieve this by implementing new property called
You need add the above in your 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 To adjust how a view controller lays out its views,
The
If your design uses opaque bars, refine
If you don’t want a scroll view’s content insets to be automatically adjusted, set
The Please refer, apple doc
|
||||||||||||||||||||||||||||||||
|
up vote36down vote |
You don't have to calculate how far to shift everything down, there's a build in property for this. In Interface Builder, highlight your view controller, and then navigate to the attributes inspector. Here you'll see some check boxes next to the words "Extend Edges". As you can see, in the first screenshot, the default selection is for content to appear under top and bottom bars, but not under opaque bars, which is why setting the bar style to not translucent worked for you. As you can somewhat see in the first screenshot, there are two UI elements hiding below the navigation bar. (I've enabled wireframes in IB to illustrate this) These elements, a UIButton and a UISegmentedControl both have their "y" origin set to zero, and the view controller is set to allow content below the top bar. This second screenshot shows what happens when you deselect the "Under Top Bars" check box. As you can see, the view controllers view has been shifted down appropriately for its y origin to be right underneath the navigation bar. This can also be accomplished programmatically through the usage of
|
||||||||||||||||||||
|
up vote22down vote |
I created my view programmatically and this ended up working for me:
Source (in topLayoutGuide section at bottom of pg.39).
|
||||||||||||||||||||||||||||||||
|
up vote8down vote |
If you want the view to have the translucent nav bar (which is kind of nice) you have to setup a contentInset or similar. Here is how I do it:
|
||||||||||||||||||||||||||||||||
|
up vote6down vote |
In your apps plist file add a row call it "View controller-based status bar appearance" and set it to NO
|
||||||||||||||||||||
|
up vote5down vote |
The simplest trick is to open the NIB file and do these two simple steps:
And THE RESULT:
|
||||||||||||||
|
up vote5down vote |
|
||
add comment |
up vote3down vote |
add the key
|
||||||||||||||
|
up vote3down vote |
I would like to expand on Stunner's answer and add an The addition would be adding: So I would suggest adding this method to your
|
||
add comment |
up vote2down vote |
To me, the simplest solution is to add two keys into the plist
|
||||||||
|
up vote1down vote |
I have a scenario where I use the BannerViewController written by Apple to display my ads and a ScrollViewController embedded in the BannerViewController. To prevent the navigation bar from hiding my content, I had to make two changes. 1) Modify BannerViewController.m
2) Modify my ScrollViewContoller
Now the ads show up correctly at the bottom of the view instead of being covered by the Navigation bar and the content on the top is not cut off. |
欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 330987132 | Go:217696290 | Python:336880185 | 做人要厚道,转载请注明出处!