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中更改顶部栏下的设置和调整滚动视图,迫使框架到一个新的区域。

一图胜千言万语:


当前回答

我把它的工作大小设置为自由形式

其他回答

如果你还需要支持iOS 6,你必须有条件地把它下移。也就是说,在iOS 7中,你只需要将它向下移动20个点(通过帧操作或使用自动布局),而在iOS 6中,你可以不动它。我不相信你们能在IB中做这个,所以你们必须在代码中做。

EDIT

你可以在IB中,通过使用iOS6/iOS7增量。在iOS 7中设置你的位置,然后在iOS 6中设置Y为-20点。更多信息请参见这个SO问题。

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

对于Xcode 7,取消导航栏的“半透明”复选标记对我来说很有效。

下面的解决方案在代码中工作得很好,不需要使用神奇的常量,并解释了用户改变大小类,例如通过旋转或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);
}

如果你用编程的方式做事情,并且使用一个没有UINavigationController的UITableViewController,你最好的选择是在viewDidLoad中做以下事情:

斯威夫特3

self.tableView.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)

早些时候,迅速

self.tableView.contentInset = UIEdgeInsetsMake(20.0f, 0.0f, 0.0f, 0.0f);

UITableViewController仍然会滚动到状态栏后面,但当滚动到顶部时,不会在状态栏下面。