Status bar and navigation bar appear over my view's bounds in iOS 7
转自:http://stackoverflow.com/questions/17074365/status-bar-and-navigation-bar-appear-over-my-views-bounds-in-ios-7
Question:
I recently downloaded Xcode DP to test my apps in iOS . 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 viewDidLayoutSubviews, I print the view's bounds:
{{, }, {, }}
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.
How can I fix this issue?
Update:
I've found a solution for this specific problem. Set the navigation bar's translucent property to NO:
self.navigationController.navigationBar.translucent = 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.
|
You can achieve this by implementing a new property called
You need to 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 |
|||||||||||||||||||||
|
|
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
|
|||||||||||||||||
|
|
I created my view programmatically and this ended up working for me:
Source (in topLayoutGuide section at bottom of pg.39). |
|||||||||||||||||||||
|
|
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:
|
|||||||||||||||||||||
|
|
|
|||
|
In your apps plist file add a row, call it "View controller-based status bar appearance" and set it to NO. |
|||||
|
|
The simplest trick is to open the NIB file and do these two simple steps:
And the result:
|
|||||||||
|
|
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
|
||||
|
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. |
|||
|
To me, the simplest solution is to add two keys into the plist
|
|||||
|
|
Add the key "View Controller-based status bar appearance" from the dropdownlist as a row in
|
||||
|
Steps For Hide the status bar in iOS 7: 1.Go to your application info.plist file. 2.And Set, View controller-based status bar appearance : Boolean NO Hope i solved the status bar issue..... |
Status bar and navigation bar appear over my view's bounds in iOS 7的更多相关文章
- 与Status Bar和Navigation Bar相关的一些东西
Android Navigation Bar Status Bar 与StatusBar和NavigationBar相关的东西有两种,一是控制它们的显示与隐藏,二是控制它们的透明与否及背景. 在2 ...
- Navigation bar 的注意事项
Navigation bar 的注意事项 Bar button item 使用 button 作为 custom view,初始化 isEnabled 为 false,注意顺序 需要设置 bar bu ...
- Customizing Navigation Bar and Status Bar
Like many of you, I have been very busy upgrading my apps to make them fit for iOS 7. The latest ver ...
- [Android] 获取系统顶部状态栏(Status Bar)与底部导航栏(Navigation Bar)的高度
Android一些设备都有上下两条bar,我们可以获取这些bar的信息.下面放上获取高度的代码.代码注释和其他方法有空再放. 原文地址请保留http://www.cnblogs.com/rossone ...
- [工作积累] Android: Hide Navigation bar 隐藏导航条
https://developer.android.com/training/system-ui/navigation.html View decorView = getWindow().getDec ...
- Android hide Navigation bar
最近一个app需要隐藏Navigation bar导航栏. 参考文档 http://blog.csdn.net/zwlove5280/article/details/52823128 http://j ...
- IOS7 状态栏和 Navigation Bar重叠的问题解决
一 Status bar重叠问题: 方法一:隐藏Status bar 在plist里面增加2个变量 Status bar is initially hidden -> YES Vie ...
- android隐藏底部虚拟键Navigation Bar实现全屏
隐藏底部虚拟键Navigation Bar实现全屏有两种情况 第一种:始终隐藏,触摸屏幕时也不出现 解决办法:同时设置以下两个参数 View.SYSTEM_UI_FLAG_HIDE_NAVIGATIO ...
- 非常不错的Navigation Bar效果
非常不错的Navigation Bar效果,该源码转载于源码天堂的,大家可以了解一下吧,多视图应用程序中,我们常常使用到自定义UINavigationBar来完成导航条的设置. 源码我就不上传了,大家 ...
随机推荐
- 给mysql配置phpmyadmin可视化管理工具
1.配置IIS管理器1.控制面板——程序——程序和功能——启用或关闭windows功能并稍稍等候2.internet information services3.勾选ftp服务器.web管理工具.应用 ...
- django之环境变量配置
1.配置python变量环境,C:\Python27\;C:\Python27\Scripts\ 2.配置django变量环境,C:\Python34\Lib\site-packages\Django ...
- RHEL6.5 grub修复测试
RHEL6.5 grub修复测试 1.删除系统中的grub.conf配置文件,然后重启系统#rm -f /boot/grub/grub.conf#reboot 2.重启后,系统进入到grub界面:gr ...
- android中巧妙更改spinner、AutoCompleteTextView分割线的颜色值(spinner AutoCompleteTextView divider color)
这个问题本来是个不大的问题,但是遇到了就会很郁闷,Android控件的api本身就不太够强大,这个小属性找了好久没找到,今天终于解决,分享给所有遇到这个问题的朋友. spinner下拉列表中间有一条黑 ...
- java实现https ssl请求url
import java.io.*;import java.net.*;import java.security.*;import java.security.cert.*;import java.ut ...
- appfuse的使用方法
2008-07-27 appfuse是如何使用的? 比如我想编写一个 struts+spring+hibernate+ajax的网站,如何用appfuse加速我的开发进度呢 ----------- ...
- idea及webstorm破解方法(转)
首先要做的就是去下载 破解的jar包,本来要上传的但是检测资源已经存在,但是能下到的地方很多,这里贴出一个链接 点击:链接链接. 点击下载上图当中的jar包 . 然后找到自己安装webstorm的安装 ...
- Python函数的静态变量
C语言中,在函数内部可以定义static类型的变量,这个变量是属于这个函数的全局对象.在Python中也可以实现这样的机制. def f(): if not hasattr(f, 'x'): f.x ...
- jenkins 图文教程 下载 --》安装--》更改默认端口号,附自启动脚本
参考文章: 1.http://www.ibm.com/developerworks/cn/java/j-lo-jenkins/ 2.http://blog.csdn.net/zhaolixin007/ ...
- 搭建HBase+thrift+php环境
http://www.beauty-soft.net/blog/ceiba/hadoop/2013-05-19/644.html http://www.360doc.com/content/11/07 ...









