The first screen of my application is a UITableViewController without a navigation bar, which means that the content flows under the status bar so there's a lot of text collisions. I've adjusted both the properties for Under top bars and Adjust scroll view insets which do actually stop it from scrolling under, but at the cost of keeping the top of the table view under. I've attempted to set the UITableView frame to offset by 20 pixels, but it doesn't appear to take effect and as I currently need the app to be compatible with iOS 6 I can't jump to iOS 7 Storyboards to force autolayout to use the top height guide. Has anyone found a solution that works for both versions?

我尝试过的事情:设置edgesForExtendedLayout,在Storyboard中更改顶部栏下的设置和调整滚动视图,迫使框架到一个新的区域。

一图胜千言万语:


当前回答

Abrahamchez的解决方案 https://developer.apple.com/library/ios/qa/qa1797/_index.html 为我工作如下。我有一个单独的UITableviewcontroller作为我的初始视图。我尝试过偏移码和嵌入navcon,但都没有解决状态栏透明度。

添加一个Viewcontroller并将其作为初始视图。这将显示关键的顶部和底部布局指南。

将旧的Tableview拖到新控制器的View中。

做所有的事情来改造表到新的控制器:

修改旧的视图controller.h文件,从UIViewController继承/子类,而不是UITableViewController。

添加UITableViewDataSource和UITableViewDelegate到视图控制器的。h。

重新连接故事板中需要的任何东西,比如搜索栏。

最重要的是设置约束条件,就像苹果问答一样。我没有插入工具栏。不确定确切的顺序。但是布局指南上出现了一个红色图标,可能是在我构建的时候。我点击它,让Xcode安装/清除约束。

然后我点击所有地方,直到我找到垂直空间约束,并将其顶部值从-20改为0,它完美地工作了。

其他回答

Abrahamchez的解决方案 https://developer.apple.com/library/ios/qa/qa1797/_index.html 为我工作如下。我有一个单独的UITableviewcontroller作为我的初始视图。我尝试过偏移码和嵌入navcon,但都没有解决状态栏透明度。

添加一个Viewcontroller并将其作为初始视图。这将显示关键的顶部和底部布局指南。

将旧的Tableview拖到新控制器的View中。

做所有的事情来改造表到新的控制器:

修改旧的视图controller.h文件,从UIViewController继承/子类,而不是UITableViewController。

添加UITableViewDataSource和UITableViewDelegate到视图控制器的。h。

重新连接故事板中需要的任何东西,比如搜索栏。

最重要的是设置约束条件,就像苹果问答一样。我没有插入工具栏。不确定确切的顺序。但是布局指南上出现了一个红色图标,可能是在我构建的时候。我点击它,让Xcode安装/清除约束。

然后我点击所有地方,直到我找到垂直空间约束,并将其顶部值从-20改为0,它完美地工作了。

我认为使用UITableViewController的方法可能和你们之前做的有点不同。这对我来说很有效,但你可能不会喜欢。我所做的是有一个视图控制器和一个指向UItableViewController的容器视图。这样我就可以使用TopLayoutGuide提供给我的故事板。只要把约束添加到容器视图,你就可以兼顾iOS7和iOS6了。

在你的故事板上选择UIViewController,取消选中顶部栏下的扩展边。 为我工作。 : )

- (void) viewDidLayoutSubviews {
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
        self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
        if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
            self.edgesForExtendedLayout = UIRectEdgeNone;   // iOS 7 specific
        CGRect viewBounds = self.view.bounds;
        CGFloat topBarOffset = self.topLayoutGuide.length;
        viewBounds.origin.y = topBarOffset * -1;
        self.view.bounds = viewBounds;
        self.navigationController.navigationBar.translucent = NO;
    }
}

https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/SupportingEarlieriOS.html#//apple_ref/doc/uid/TP40013174-CH14-SW1

下面的解决方案在代码中工作得很好,不需要使用神奇的常量,并解释了用户改变大小类,例如通过旋转或ipad上的并排应用程序:

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
    [super traitCollectionDidChange:previousTraitCollection];
    // Fix up content offset to ensure the tableview isn't underlapping the status bar.
    self.tableView.contentInset = UIEdgeInsetsMake(self.topLayoutGuide.length, 0.0, 0.0, 0.0);
}