我有我的collectionView的代码,可以调整内容,使其位于导航栏下面。
collectionView.contentInsetAdjustmentBehavior = .never
let tabBarHeight = self.tabBarController?.tabBar.bounds.height
let navBarHeight = self.navigationController?.navigationBar.bounds.height
self.edgesForExtendedLayout = UIRectEdge.all
self.collectionView.contentInset = UIEdgeInsets(top: navBarHeight!, left: 0.0, bottom: tabBarHeight!, right: 0.0)这在iOS 11上的所有其他设备上都能很好地工作,除了iPhone X,在iPhone X上,内容位于导航栏和应用程序启动工具栏后面。
对于iPhone X,有什么是我特别缺少的吗?
谢谢
发布于 2018-04-10 13:05:41
我想你忘了计算状态栏的高度了。在iPhone X之前,状态栏的高度为20 it,在iPhoneX中为44 it。这就是你看不到完整细胞的原因。
为此,从superview添加约束并编写以下代码:
cv.contentInsetAdjustmentBehavior = .never
let tabBarHeight = self.tabBarController?.tabBar.bounds.height ?? 0
let statuBarHeight = UIApplication.shared.statusBarFrame.height
let navBarHeight = self.navigationController?.navigationBar.bounds.height ?? 0
self.edgesForExtendedLayout = UIRectEdge.all
cv.contentInset = UIEdgeInsets(top: navBarHeight+statuBarHeight, left: 0.0, bottom: tabBarHeight, right: 0.0)希望这会有所帮助:)
https://stackoverflow.com/questions/49715327
复制相似问题