【问题标题】:How to stop the status bar covering the navigation bar in iOS6如何在iOS6中停止状态栏覆盖导航栏
【发布时间】:2013-02-05 17:33:55
【问题描述】:

这是我的问题....

这发生在:

  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 上不起作用,因为没有调用 shouldAutorotateToInterfaceOrientation。但是,使用它的替换:willRotateToInterfaceOrientation 也不起作用。有什么想法吗?

【问题讨论】:

  • shouldAutorotateToInterfaceOrientation 的替换不是willRotateToInterfaceOrientation。是supportedInterfaceOrientations。
  • @rmaddy 同意,但在 ios 5 中它有另一个目的 - 让您知道它即将旋转屏幕。
  • 这不是真的。对shouldAutorotateToInterfaceOrientation 的调用绝不表示视图控制器即将旋转。其目的是询问是否允许某些轮换。 willRotateToInterfaceOrientation 方法用于指示轮换实际上即将发生。请记住,这些方法是关于视图控制器,而不是屏幕。
  • @rmaddy - 好吧,显然你是对的! willRotateToInterfaceOrientation 也是在 iOS 5 上调用的,我还以为是 iOS 6 的新方法。
  • willRotateToInterfaceOrientation 从 iOS 2.0 开始就存在了。

标签: iphone ios cocoa-touch


【解决方案1】:

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

【讨论】:

  • 这不起作用。帧始终报告为 480 x 268(旋转之前/之后/切换状态栏)。设置框架没有效果。谢谢你的回答。
  • 你检查我的另一个解决方案了吗?
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    好的,答案是在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];
            });
        }
    }
    

    【讨论】:

      【解决方案4】:

      我打电话后

      dismissViewControllerAnimated

      这个方法,然后调用

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

      出现这个问题。

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

      【讨论】:

        猜你喜欢
        • 2021-05-08
        • 1970-01-01
        • 2012-03-24
        • 2019-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-13
        • 1970-01-01
        相关资源
        最近更新 更多