当 iPhone X 横向使用时,您应该检查 safeAreaInsets 以在左侧和右侧制作适当大的装订线。 UITableView 有新的insetsContentViewsToSafeArea
属性(默认 true)自动将单元格内容保留在安全区域。
我很惊讶 UICollectionView 似乎没有类似的东西。我希望对于垂直滚动的集合视图,在横向时,左侧和右侧将插入到安全区域(相反,如果需要在纵向时,水平滚动集合视图将插入到安全区域)。
确保此行为的最简单方法似乎是添加到集合视图控制器:
- (void)viewSafeAreaInsetsDidChange {
[super viewSafeAreaInsetsDidChange];
UIEdgeInsets contentInset = self.collectionView.contentInset;
contentInset.left = self.view.safeAreaInsets.left;
contentInset.right = self.view.safeAreaInsets.right;
self.collectionView.contentInset = contentInset;
}
...假设 contentInset.left/right 通常为零。
(注意:是的,对于 UICollectionViewController,需要self.view.safeAreaInsets
;在调用时,更改为safeAreaInsets
奇怪的是还没有传播到self.collectionView
)
我错过了什么吗?该样板很简单,但现在它实际上是必要的every接触屏幕边缘的集合视图。苹果没有提供默认启用此功能的功能,这似乎很奇怪。
有同样的问题。这对我有用:
override func viewDidLoad() {
if #available(iOS 11.0, *) {
collectionView?.contentInsetAdjustmentBehavior = .always
}
}
The 文档 https://developer.apple.com/documentation/uikit/uiscrollviewcontentinsetadjustmentbehavior为了.always
枚举案例说:
始终在内容调整中包含安全区域插图。
该解决方案在手机旋转的情况下也能正常工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)