#pragma mark - 解决iOS7状态栏问题
- (void)viewWillAppear:(BOOL)animated
{
// 注意点:自定义布局方法必须放在隐藏或显示导航栏(如果有的话)这句话后面,不然会乱;
self.navigationController.navigationBarHidden = YES;
// 自定义布局
[self autoAdaptionLayer];
}
// 自定义布局
- (void)autoAdaptionLayer
{
// 如果是IOS7.0以上
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
self.edgesForExtendedLayout = UIRectEdgeNone; // 非全屏布局
self.extendedLayoutIncludesOpaqueBars = NO; // 当导航栏使用不透明图片,View不延伸之Bar下面
self.modalPresentationCapturesStatusBarAppearance = NO;
[self setNeedsStatusBarAppearanceUpdate]; // 设置StatusBar的样式
CGRect viewBounds = self.view.bounds;
// ******* 这个修订很重要 *******
if(viewBounds.size.height == 548)
viewBounds.size.height = 568;
if(viewBounds.size.height == 460)
viewBounds.size.height = 480;
CGFloat topBarOffset = 0; // self.topLayoutGuide.length;
CGFloat myHeight = viewBounds.size.height;
// 存在导航栏控制器
if (self.navigationController)
{
// 导航栏隐藏的时候(底部空间高度需要-20)
if (self.navigationController.navigationBarHidden)
{
viewBounds.origin.y = topBarOffset - 20;
viewBounds.size.height = myHeight - 20;
}
else // 导航栏显示的时候(底部空间高度需要-84)
{
viewBounds.origin.y = topBarOffset * -1;
viewBounds.size.height = myHeight - 64;
}
}
else
{
viewBounds.origin.y = topBarOffset -20;
viewBounds.size.height = myHeight - 20;
}
self.view.bounds = viewBounds;
}
// IOS7.0以下
else
{
CGRect viewBounds = self.view.bounds;
// ******* 这个修订很重要 *******
if(viewBounds.size.height == 548)
viewBounds.size.height = 568;
if(viewBounds.size.height == 460)
viewBounds.size.height = 480;
CGFloat myHeight = viewBounds.size.height;
// 判断是否存在导航栏控制器
if (self.navigationController)
{
// 导航栏隐藏的时候(底部空间高度需要-20)
if (self.navigationController.navigationBarHidden)
{
viewBounds.size.height = myHeight;
}
else // 导航栏显示的时候(底部空间高度需要-22)
{
viewBounds.size.height = myHeight - 22;
}
}
else
{
viewBounds.size.height = myHeight;
}
self.view.bounds = viewBounds;
}
}
// 设置StatusBar的样式
// 上面这句方法用于刷新显示statusBar的样式和是否隐藏,如果需要就在当前使用的VC中重写下面两个方法
- (UIStatusBarStyle)preferredStatusBarStyle
{
// UIStatusBarStyleDefault
// UIStatusBarStyleLightContent
// UIStatusBarStyleBlackTranslucent
// UIStatusBarStyleBlackOpaque
return UIStatusBarStyleLightContent; // 会多次调用
}
- (BOOL)prefersStatusBarHidden
{
return NO; // 会多次调用
}