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,它完美地工作了。
这是一个Swift 2.3。(Xcode 8.0)解决方案。我已经创建了UITableView的子类。
class MYCustomTableView: UITableView
{
override func drawRect(rect: CGRect) {
super.drawRect(rect)
contentInset = UIEdgeInsetsZero
}
}
内容插入应该始终为零(默认情况下)。我手动设置为零。你也可以添加一个check方法来检查,如果它不是你想要的,只要得到正确的rect就可以了。这个变化只会在tableview被绘制时反映出来(这并不经常发生)。
不要忘记在你的IB中更新TableView(在TableViewController中或只是在你的ViewController中的TableView中)。