经过几个小时的实验,终于从虐心风中走出,试了几种导航状态栏隐藏显示时候视图位置的彼变化,以下就抛下砖。欢迎拍板
// 这个基于模态视图的时候,模态视图需要加上
UINavigationController,将navgationBar隐藏时候用,状态条时间颜色风格在plist文件中设置。。
"Statusbarisinitiallyhidden" -> NO,
View controller-based status bar appearance ->NO,控制系统状态栏是否显示,如果不显示,需要在window上加20像素的view作为状态栏,。。。
只有在为YES时候以下方法才会调用
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;//UIStatusBarStyleBlackTranslucent;
}
- (BOOL)prefersStatusBarHidden
{
return NO;
}
//目的:用于iOS7和iOS6适配,和保留之前的坐标编码习惯,不用刻意加减
/*方法1:
*1。在vc中重写viewDidLayoutSubviews方法
*2。是用下面2个方法之一;
*3。frame为ios6风格,状态栏和导航栏为平铺
*4。bounds为ios7风格,状态栏和导航栏为覆盖
*5。优点,所有subview的坐标都一ios6的标准进行编写,支持push和present
*6。缺点,在push中每个vc都需要重写viewDidLayoutSubviews方法;
*/
void
IOS
7
ToIOS
6
ofFrame(
UIViewController
*vc);
void
IOS
7
ToIOS
6
ofBounds(
UIViewController
*vc);
void
IOS
7
ToIOS
6
ofFrame(
UIViewController
*vc)
{
if
(IsIOS
7
) {
CGRect
rect = vc
.view
.frame
;
vc
.view
.frame
= CGRectMake((rect
.origin
.x
), (rect
.origin
.y
+(IsIOS
7
?vc
.topLayoutGuide
.length
:
0
)), (CGRectGetWidth(rect)), (CGRectGetHeight(rect)-(IsIOS
7
?vc
.topLayoutGuide
.length
:
0
)));
}
}
void
IOS
7
ToIOS
6
ofBounds(
UIViewController
*vc)
{
if
(IsIOS
7
) {
CGRect
rect = vc
.view
.bounds
;
if
(rect
.origin
.y
!= -
1
*vc
.topLayoutGuide
.length
) {
vc
.view
.bounds
= CGRectMake((rect
.origin
.x
), (rect
.origin
.y
+(IsIOS
7
?vc
.topLayoutGuide
.length
*(-
1
):
0
)), (CGRectGetWidth(rect)), (CGRectGetHeight(rect)));
}
}
}
/*方法2:
*1.在vc的init或viewdidload中使用IOS7宏即可;
*2.状态栏和导航栏为平铺
*3.优点:所有subview的坐标都一ios6的标准进行编写,支持push,背景frame值同ios6
*4.缺点:在push中每个vc都需要写,不支持present;
*/
#define IOS7 if([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue]>=7)\
{
self
.extendedLayoutIncludesOpaqueBars
=
NO
;\
self
.modalPresentationCapturesStatusBarAppearance
=
NO
;\
self
.edgesForExtendedLayout
=
UIRectEdgeNone
;}
/*方法3:
*1.使用self.navigationController.navigationBar.translucent =NO;
*2.状态栏和导航栏为平铺
*3.优点:所有subview的坐标都一ios6的标准进行编写,支持push,背景frame值同ios6,只需要设置一次
*4.缺点:必须有nav;对于present的vc必须为nav,此时edgesForExtendedLayout 设置为UIRectEdgeAll,为None时视图会被状态栏遮挡
*/
/*方法4:
*1.重新定义CGRECT;
*2.状态栏和导航栏为覆盖
*3.优点:随时可以用
*/
#define IsIOS7 ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue]>=7)
#define CGRECT_NO_NAV(x,y,w,h) CGRectMake((x), (y+(IsIOS7?20:0)), (w), (h))
#define CGRECT_HAVE_NAV(x,y,w,h) CGRectMake((x), (y+(IsIOS7?64:0)), (w), (h))