iOS 7 status bar like iOS 6

前端 未结 5 1319
南笙
南笙 2021-02-08 04:05

I have an app with a support landscape and portrait mode. And I need the same behavior status bar like on iOS 6. What is the simplest way to do this?

I\'ve tried the sol

5条回答
  •  逝去的感伤
    2021-02-08 04:41

    I recently had to solve a similar problem, and I approached it in a slightly different way...

    The approach was to use an extra view controller that acted as a container view controller for what was originally my rootViewController. First, i set up a container like this:

    _containerView = [[UIView alloc] initWithFrame:[self containerFrame]];
    _containerView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    _containerView.clipsToBounds = YES;
    
    [self.view addSubview:_containerView];
    [self.view setBackgroundColor:[UIColor blackColor]];
    
    [UIApplication.sharedApplication setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
    

    where the containerFrame was defined like this:

    - (CGRect)containerFrame
    {
        if ([MyUtilityClass isSevenOrHigher])
        {
            CGFloat statusBarHeight = [MyUtility statusBarHeight]; //20.0f
            return CGRectMake(0, statusBarHeight, self.view.bounds.size.width, self.view.bounds.size.height - statusBarHeight);
        }
    
        return self.view.bounds;
    }
    

    Finally, I added what was originally my rootViewController as a childViewController of the new one:

    //Add the ChildViewController
    self.childController.view.frame = self.containerView.bounds;
    self.childController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [self addChildViewController:self.childController];
    [self.containerView addSubview:self.childController.view];
    [self.childController didMoveToParentViewController:self];
    

    Things to note: - Modal view controllers will still be presented in the iOS7 style, so I still have to account for that somehow.

    Hope this helps someone!

提交回复
热议问题