[英]Swift: safe area on iPhone
I have ViewController
with collectionView
and collectionView
bottom, top, leading, trailing constraints to superview. 我有ViewController
和collectionView
和collectionView
底部,顶部,前导,尾随约束以进行超级视图。 And on iPhone 8 my screen look like this: 在iPhone 8上,我的屏幕如下所示:
And for another devices all looks fine. 对于其他设备,一切看起来都很好。 But on iPhone X look like this: 但是在iPhone X上看起来像这样:
I use this code for my cells: 我将以下代码用于单元格:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let offset: CGFloat = 10
let width = collectionView.bounds.width / 3 - offset * 4
let a: CGFloat = width / 2
let b: CGFloat = a * 3 + a * 0.65
let height = b
return CGSize(width: width, height: height)
}
How to fix it? 如何解决?
Update 更新资料
constraints: 约束:
With your details I got below output. 根据您的详细信息,我的输出低于输出。
NOTE: In landscape mode safearea of top is zero. 注意:在横向模式下,顶部的安全区域为零。
Constraints : 限制条件:
SizeForItem : SizeForItem:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let offset: CGFloat = 10
let width = collectionView.bounds.width / 3 - offset * 4
let a: CGFloat = width / 2
let b: CGFloat = a * 3 + a * 0.65
let height = b
return CGSize(width: width, height: height)
}
Edit : Check is this o/p is not for you or not. 编辑:检查此o / p是否不适合您。 So that I will explain. 所以我会解释。 And if you wanted to cover the safe area then it is not possible. 而且,如果您想覆盖安全区域,则不可能。
Iphone X iPhone X
Iphone 8 苹果手机8
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.