iOS 7 - 状态栏重叠在视图上

109

我有一个ViewControllerUINavigationcontroller中,但导航栏是隐藏的。当我在iOS 7上运行应用程序时,状态栏显示在我的视图顶部。有没有办法避免这种情况?

我不想写任何特定于操作系统的代码。

输入图像说明

我尝试将 View controller-based status bar appearance 设置为NO,但没有解决问题。


我已经发布了我的答案,以在iOS 7中显示类似于iOS 6的状态栏。https://dev59.com/fGMl5IYBdhLWcg3wknsT#19044681 - Desert Rose
2
你需要调整y坐标和delta值来解决状态栏问题。这个链接可能会对你有帮助:https://dev59.com/IGMk5IYBdhLWcg3wxAvy。 - Ganapathy
14个回答

1
Vincent的答案edgesForExtendedLayout对我有用。
这些宏有助于确定操作系统版本,使其更容易。
// 7.0 and above 
#define IS_DEVICE_RUNNING_IOS_7_AND_ABOVE() ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) 

// 6.0, 6.0.x, 6.1, 6.1.x
#define IS_DEVICE_RUNNING_IOS_6_OR_BELOW() ([[[UIDevice currentDevice] systemVersion] compare:@"6.2" options:NSNumericSearch] != NSOrderedDescending) 

将这些宏添加到您项目的prefix.pch文件中,可以在任何地方访问

if(IS_DEVICE_RUNNING_IOS_7_AND_ABOVE())
{
 //some iOS 7 stuff
 self.edgesForExtendedLayout = UIRectEdgeNone;
}

if(IS_DEVICE_RUNNING_IOS_6_OR_BELOW())
{
 // some old iOS stuff
}

1
对我来说,self.edgesForExtendedLayout = UIRectEdgeNone; 不起作用... 有什么原因吗? - Fahim Parkar

1

0

在从YTPlayer的横向视图返回后,我的状态栏和导航栏重叠了。尝试了@comonitos版本但在我的iOS 8上无法工作,这是我的解决方案。

- (void)fixNavigationBarPosition {
    if (self.navigationController) {
        CGRect frame = self.navigationController.navigationBar.frame;
        if (frame.origin.y != 20.f) {
            frame.origin.y = 20.f;
            self.navigationController.navigationBar.frame = frame;
        }
    }
}

每当您想要固定导航栏的位置时,只需调用此函数。我在YTPlayerViewDelegate的playerView:didChangeToState:中进行了调用。

- (void)playerView:(YTPlayerView *)playerView didChangeToState:(YTPlayerState)state {
    switch (state) {
        case kYTPlayerStatePaused:
        case kYTPlayerStateEnded:
            [self fixNavigationBarPosition];
            break;
        default:
    }
}

0
如果您想无论如何启用“使用自动布局”,请在viewdidload中放置以下代码。
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) 
{
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.automaticallyAdjustsScrollViewInsets = NO;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接