如何使用Objective C iOS从iPhone X的表视图顶部删除额外的空间
我已经开发了Objective C中的应用程序,在所有的iPhone手机上都能正常工作。 但是,当我在iPhone X模拟器中运行这个应用程序,然后我不知道我是如何获得一些额外的空间(约20-22像素)在UITableView的顶部。 我尝试了所有这些解决scheme,但是下面没有一个帮助我:
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; }
我知道这可以通过设置我的表视图contentInset像:
tblProducts.contentInset = UIEdgeInsetsMake(-30, 0, 0, 0);
有没有其他解决scheme来解决iPhone X的这个问题?
我在ViewDidLoad中检查了我的表格视图框架,它是(0,64,WIDTH,HEIGHT),状态栏有问题吗?
请build议我。 先谢谢你!
你可以尝试设置contentInsetAdjustmentBehavior
属性为Never
。
在Swift中,我在UICollectionView
有这个:
if #available(iOS 11.0, *) { collectionView.contentInsetAdjustmentBehavior = .never }
在Objective-C中, UITableView
同样适用,像这样设置:
if (@available(iOS 11.0, *)) { [_tableView setContentInsetAdjustmentBehavior: UIScrollViewContentInsetAdjustmentNever]; }
如果任何人正在寻找故事板的答案,然后在故事板中select你的UITableView,只是改变内容插入永不,如下图所示链接