ios - 如何使用 Objective C iOS 从 iPhone X 中的表格 View 顶部删除多余空间

标签 ios objective-c iphone uitableview iphone-x

我已经用 Objective C 开发了一个应用程序,它在所有 iPhone 手机上都运行良好。但是当我在 iPhone X 模拟器中运行这个应用程序时,我不知道如何在 UITableView 的顶部获得一些额外的空间(大约 20-22 像素)。我尝试了所有这些解决方案,但以下都没有帮助我:

self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];

self.edgesForExtendedLayout = UIRectEdgeNone;

[tblProducts setSectionHeaderHeight:0];

self.automaticallyAdjustsScrollViewInsets = NO;

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

我知道这可以通过像这样设置我的 TableView contentInset 来实现:

tblProducts.contentInset = UIEdgeInsetsMake(-30, 0, 0, 0);

有没有其他解决方案可以解决 iPhone X 的这个问题?

我在ViewDidLoad中检查了我的table view frame,是(0, 64, WIDTH, HEIGHT),是不是Status bar有问题?

请给我建议。在此先感谢您!

最佳答案

您可以尝试将 contentInsetAdjustmentBehavior 属性设置为 Never

在 Swift 中,我在 UICollectionView 中有这个:

if #available(iOS 11.0, *) {
    collectionView.contentInsetAdjustmentBehavior = .never
}

在Objective-C中,同样适用于UITableView,这样设置:

if (@available(iOS 11.0, *)) {
    [_tableView setContentInsetAdjustmentBehavior: UIScrollViewContentInsetAdjustmentNever];
}

关于ios - 如何使用 Objective C iOS 从 iPhone X 中的表格 View 顶部删除多余空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46639918/

相关文章:

ios - 将表格单元格添加到 iOS 中特定部分的表格

ios - 使用 UILocalizedIndexedCollat​​ion sectionForObject :collationStringSelector 的动态选择器

ios - 在 Tableview 中偏移 HeaderView 以显示类似卡片

ios - 是否允许添加打开 Safari 的 UITabBarItem?

ios - 降低加速度计的灵敏度

iphone - 如何删除 UITextView 的最后一个空行?

iphone - 全局检测触摸

iphone - 使用 GraphAPI 或 FQL Query 或 HTTP Post 方法为 Facebook Post 点赞

ios - 自定义后退指示器图像和 iOS 11

objective-c - 真的没有办法捕获退格字符吗?