iPhone - Remove status bar programmatically

前端 未结 6 1751
刺人心
刺人心 2021-01-02 09:17

I have made an app that implements the iPhone\'s camera. When the user finishes picking their image, the status bar reappears! How would I make sure that the status bar sta

6条回答
  •  时光取名叫无心
    2021-01-02 09:53

    Grand central dispatch is your friend, using this method you won't see the status bar appear at all when the picker is displayed or afterwards

    - (void)hideStatusBar
    {
        if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)])
        {
            [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
        }
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
    }
    
    - (BOOL)prefersStatusBarHidden {
        return YES;
    }
    
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    
        [self hideStatusBar];
        double delayInSeconds = 0.2;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            [self hideStatusBar];
        });
    }
    

提交回复
热议问题