View Debug 中的 Collection View Frame 与代码不同
Collection View Frame in View Debug is different from code
通过 View Debug 调试自定义 UICollectionView 时,其宽度为 829
,但通过代码访问时,其宽度为 820
。我错过了什么?
可视化调试:
代码:
func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAt: IndexPath) -> CGSize
{
let widthForCulculation = self.frame.size.width // 820.0
...
return CGSize(width: segmentWidth, height: segmentHeight)
}
非常 hacky 的方式,但是在布局子视图时尝试使布局无效
var width : CGFloat = 0
override func layoutSubviews() {
super.layoutSubviews()
if (self.width != self.frame.size.width)
{
self.width = self.frame.size.width
self.collectionViewLayout.invalidateLayout()
}
}
通过 View Debug 调试自定义 UICollectionView 时,其宽度为 829
,但通过代码访问时,其宽度为 820
。我错过了什么?
可视化调试:
代码:
func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAt: IndexPath) -> CGSize
{
let widthForCulculation = self.frame.size.width // 820.0
...
return CGSize(width: segmentWidth, height: segmentHeight)
}
非常 hacky 的方式,但是在布局子视图时尝试使布局无效
var width : CGFloat = 0
override func layoutSubviews() {
super.layoutSubviews()
if (self.width != self.frame.size.width)
{
self.width = self.frame.size.width
self.collectionViewLayout.invalidateLayout()
}
}