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

一图胜千言万语:


当前回答

我有一个UITableView顶部的UISearchBar和以下工作;

self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);
self.tableView.contentOffset = CGPointMake(0, -20);

分享和享受…

其他回答

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

EDIT

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

- (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

我发现最简单的方法,尤其是当你在标签栏中添加表格视图时,首先添加一个视图,然后在该视图中添加表格视图。这将为您提供您正在寻找的最高边际指导。

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

这是一个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中)。