在iPhone X上,UIView中的safeAreaInsets为0 [英] safeAreaInsets in UIView is 0 on an iPhone X
问题描述
我正在更新我的应用程序以使其适合iPhoneX.除一个视图外,到目前为止,所有视图都可以正常工作.我有一个视图控制器,它提供了一个覆盖整个屏幕的自定义UIView.在我使用UIScreen.main.bounds
查找所有布局之前的视图大小之前(我需要使用它来为collectionView放置正确的itemSize).我以为现在我可以做些类似的事情
UIScreen.main.bounds.size.height - safeAreaInsets.bottom
以获取正确的可用大小.问题是,在iPhone X(模拟器)上尝试使用safeAreaInsets会返回(0,0,0,0).有任何想法吗?在其他视图中,我得到了safeAreaInsets的正确数字.
I am updating my app to adapt it for iPhone X. All views work fine by now except one. I have a view controller that presents a custom UIView that covers the whole screen. Before I was using UIScreen.main.bounds
to find out the size of the view before all layout was done (I need it for putting the correct itemSize for a collectionView). I thought that now I could do something like
UIScreen.main.bounds.size.height - safeAreaInsets.bottom
to get the right usable size. The problem is, safeAreaInsets returns (0,0,0,0) trying on an iPhone X (Simulator). Any ideas? In other views, I get the right numbers for safeAreaInsets.
谢谢!
推荐答案
我已经弄清楚了解决方案:我正在视图的init
中完成所有实现. safeAreaInsets在layoutSubviews()
I already figure out the solution: I was doing all the implementation in the init
of the view. safeAreaInsets has the correct size in layoutSubviews()
这篇关于在iPhone X上,UIView中的safeAreaInsets为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!