繁体   English   中英

如何停止覆盖iOS6中导航栏的状态栏

[英]How to stop the status bar covering the navigation bar in iOS6

这是我的问题。

在此处输入图片说明

这种情况发生在以下情况:

  1. 使用按钮淡出状态栏。
  2. 从横向旋转180度到倒置横向。
  3. 使用按钮可以使状态栏淡出。 -现在它覆盖了导航栏。

用于切换状态栏可见性的按钮代码:

- (IBAction)toggleBar:(id)sender
{
    NSLog(@"View Frame : %@", NSStringFromCGRect(self.view.frame));

    // Toggle status bar visiblity
    BOOL isStatusBarHidden = [[UIApplication sharedApplication] isStatusBarHidden];
    [[UIApplication sharedApplication] setStatusBarHidden:!isStatusBarHidden
                                            withAnimation:UIStatusBarAnimationFade];
}

该视图始终报告其帧为480 x 288。

该问题已通过使用变通的解决方法在iOS 5上得以解决,方法是停止旋转填充空间。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIApplication sharedApplication] isStatusBarHidden])
    {
        float oldAlpha = self.navigationController.navigationBar.alpha;
        self.navigationController.navigationBar.alpha = 0.01;
        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

        double delayInSeconds = 0.0;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            self.navigationController.navigationBar.alpha = oldAlpha;
            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
        });
    }

    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

这在iOS 6 dons't工作,因为shouldAutorotateToInterfaceOrientation不叫。 但是,使用其替换: willRotateToInterfaceOrientation也不起作用。 有任何想法吗?

切换状态栏后,再次设置您的self.view.frame。

在IOS6,您应该使用这些方法。 检查这些。

- (BOOL)shouldAutorotate
{
    //returns true if want to allow orientation change
    return TRUE;
}
- (NSUInteger)supportedInterfaceOrientations
{   
     //decide number of origination tob supported by Viewcontroller.
     return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    //from here you Should try to Preferred orientation for ViewController 
}

好的答案是对willRotateToInterfaceOrientation使用相同的技巧,我曾说过这对我的问题不起作用,但我只是再次尝试了一下,就成功了。

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if ([[UIApplication sharedApplication] isStatusBarHidden])
    {
        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

        double delayInSeconds = 0.0;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
        });
    }
}

我打电话之后

dismissViewControllerAnimated

此方法,然后调用

[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];

出现此问题。

当我调用[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide]时; 首先,没问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM