-1

我试图隐藏仅适用于 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];
    }
4

5 回答 5

0

第一:在 info.plist 中将此标志View controller-based status bar appearance设置为 YES 或将其添加为新行第二:在要隐藏或查看状态栏的每个 VC 信息中
覆盖此方法。- (BOOL) prefersStatusBarHidden对于子视图控制器,您还需要实现此方法- (UIViewController *)childViewControllerForStatusBarHidden
第三:如果您在运行时更改状态栏外观,您需要调用他的方法来触发动画-setNeedsStatusBarAppearanceUpdate
所有这些方法都可以帮助您创建对状态栏外观的精细控制。
如果您需要在启动时让状态栏消失,只需在目标常规设置中标记隐藏状态栏。

于 2015-09-09T11:35:05.490 回答
0

我已经发布了一个类似问题的答案,您必须使用windowLevelUIApplication隐藏/显示statusBar. 此外,我们必须将基于 Viewcontroller 的外观属性设置info.plist为 NO。

于 2018-07-26T12:33:09.913 回答
0

在 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);
}  

它对我有用。

于 2015-09-09T11:33:53.507 回答
0

由于您只想在 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];
}
于 2015-09-09T11:41:07.147 回答
0

您可以这样做(更改 plist 文件):

set Status bar is initially hidden = YES

添加行:

View controller-based status bar appearance = NO
于 2015-09-09T11:24:57.643 回答