【问题标题】:iOS Hide status bar for iPhone 6 and 6+iOS 隐藏 iPhone 6 和 6+ 的状态栏
【发布时间】:2015-12-05 08:06:55
【问题描述】:
我正在尝试仅为 iPhone 6 和 6+ 隐藏状态栏,这是我迄今为止尝试过的。
if (screenWidth == 375) {
// Remove status bar for iPhone 6
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationFade];
}else if (screenWidth == 414){
// Remove status bar for iPhone 6 +
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationFade];
}
【问题讨论】:
标签:
ios
iphone
ios7-statusbar
【解决方案1】:
您可以这样做(更改 plist 文件):
set Status bar is initially hidden = YES
添加行:
View controller-based status bar appearance = NO
【解决方案2】:
首先:在 info.plist 中将此标志 查看基于控制器的状态栏外观设置为 YES 或将其添加为新行
第二:覆盖这个方法- (BOOL) prefersStatusBarHidden在每个你想隐藏或查看状态栏的VC信息。对于子视图控制器,您还需要实现此方法- (UIViewController *)childViewControllerForStatusBarHidden
第三:如果你在运行时改变状态栏外观你需要调用他的方法来触发动画-setNeedsStatusBarAppearanceUpdate
所有这些方法都可以帮助您创建对状态栏外观的精细控制。
如果您需要在启动时让状态栏消失,只需在目标常规设置中标记隐藏状态栏。
【解决方案3】:
既然您只想在 iPhone 6 和 iPhone 6 Plus 中隐藏状态栏,那么您可以像下面这样操作。首先将其添加到您的课程中。
#import <sys/utsname.h>
然后在你的 viewDidLoad 方法中
NSString *platform;
struct utsname systemInfo;
uname(&systemInfo);
platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
if ( [platform isEqual:@"iPhone6,1"]||[platform isEqual:@"iPhone6,2"]){
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationFade];
}
【解决方案4】:
在 viewDidLoad 中添加以下行:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
并添加新方法
- (BOOL)prefersStatusBarHidden {
return YES;
}
同时更改 info.plist 文件
View controller-based status bar appearance" = NO
还为 iPhone 6 和 6 Plus 添加条件。以下是 iPhone 6 和 6 Plus 的方法:
/*=====================================================================================================================
Checks if the device has 4.7 inch screen such as iPhone6 generation
=====================================================================================================================*/
+(BOOL) ISiPhone6
{
BOOL isIpad = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);
CGRect screenRect = [[UIScreen mainScreen] bounds];
// we need to check the maximum of width and height because some screens (the camera view while scanning) we can
// rotate to portrait or landscape and in the case the screen height and width flip
return (!isIpad && MAX(screenRect.size.height,screenRect.size.width) == 667);
}
/*=====================================================================================================================
Checks if the device has 5.5 inch screen such as iPhone6 plus
=====================================================================================================================*/
+(BOOL) ISiPhone6Plus
{
BOOL isIpad = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);
CGRect screenRect = [[UIScreen mainScreen] bounds];
// we need to check the maximum of width and height because some screens (the camera view while scanning) we can
// rotate to portrait or landscape and in the case the screen height and width flip
return (!isIpad && MAX(screenRect.size.height,screenRect.size.width) == 736);
}
它对我有用。
【解决方案5】:
我已针对类似问题发布了answer,您必须使用UIApplication 的windowLevel 来隐藏/显示statusBar。我们还必须将info.plist 中的基于Viewcontroller 的外观 属性设置为NO。