iOS 隐藏 iPhone 6 和 6+ 的状态栏
iOS Hide status bar for iPhone 6 and 6+
我正在尝试仅针对 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];
}
你可以这样做(更改 plist 文件):
set Status bar is initially hidden = YES
添加行:
View controller-based status bar appearance = NO
在 viewDidLoad 中添加以下行:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
并添加新方法
- (BOOL)prefersStatusBarHidden {
return YES;
}
同时更改 info.plist 文件
View controller-based status bar appearance" = NO
并且还为iPhone添加条件 6和6 Plus.Here是iPhone 6和6的方法 加上:
/*=====================================================================================================================
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);
}
它适合我。
首先:在 info.plist 中将此标志 View controller-based status bar appearance 设置为 YES 或将其添加为新行
第二:在您想要隐藏或查看状态栏的每个 VC 信息中覆盖此方法- (BOOL) prefersStatusBarHidden
。对于子视图控制器,您还需要实现此方法 - (UIViewController *)childViewControllerForStatusBarHidden
第三:如果你在运行时改变状态栏外观你需要调用他的方法来触发动画-setNeedsStatusBarAppearanceUpdate
所有这些方法都可以帮助您对状态栏外观进行精细控制。
如果您需要让状态栏在启动时消失,只需在您的目标常规设置中标记 隐藏状态栏。
因为你只想在 iPhone 6 和 iPhone 6 Plus 中隐藏状态栏,那么你可以像下面那样做。首先将其添加到您的 class.
#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];
}
我发过一个类似的问题,你要用UIApplication
的windowLevel
到statusBar
的hide/show。另外我们还要把info.plist
中的Viewcontrollerbased appearance属性设置为NO.
我正在尝试仅针对 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];
}
你可以这样做(更改 plist 文件):
set Status bar is initially hidden = YES
添加行:
View controller-based status bar appearance = NO
在 viewDidLoad 中添加以下行:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
并添加新方法
- (BOOL)prefersStatusBarHidden {
return YES;
}
同时更改 info.plist 文件
View controller-based status bar appearance" = NO
并且还为iPhone添加条件 6和6 Plus.Here是iPhone 6和6的方法 加上:
/*=====================================================================================================================
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);
}
它适合我。
首先:在 info.plist 中将此标志 View controller-based status bar appearance 设置为 YES 或将其添加为新行
第二:在您想要隐藏或查看状态栏的每个 VC 信息中覆盖此方法- (BOOL) prefersStatusBarHidden
。对于子视图控制器,您还需要实现此方法 - (UIViewController *)childViewControllerForStatusBarHidden
第三:如果你在运行时改变状态栏外观你需要调用他的方法来触发动画-setNeedsStatusBarAppearanceUpdate
所有这些方法都可以帮助您对状态栏外观进行精细控制。
如果您需要让状态栏在启动时消失,只需在您的目标常规设置中标记 隐藏状态栏。
因为你只想在 iPhone 6 和 iPhone 6 Plus 中隐藏状态栏,那么你可以像下面那样做。首先将其添加到您的 class.
#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];
}
我发过一个类似的问题UIApplication
的windowLevel
到statusBar
的hide/show。另外我们还要把info.plist
中的Viewcontrollerbased appearance属性设置为NO.