页面层级结构:
VC.View -> scrollView -> HeaderView -> SliderView -> CollectionView -> Cell -> RankRadioIconView -> (label、image)
Masnory警告:
(
"<MASLayoutConstraint:0x283e65980 RankRadioIconView:0x10aa0a100.left == UIView:0x10aa0a4a0.left>",
"<MASLayoutConstraint:0x283e65b60 RankRadioIconView:0x10aa0a100.right == UIView:0x10aa0a4a0.right>",
"<MASLayoutConstraint:0x283e65f20 SDAnimatedImageView:0x10aa05f10.left == RankRadioIconView:0x10aa0a100.left>",
"<MASLayoutConstraint:0x283e65ce0 SDAnimatedImageView:0x10aa05f10.right == RankRadioIconView:0x10aa0a100.right>",
"<MASLayoutConstraint:0x283e66520 UILabel:0x10aa0bfa0.left == SDAnimatedImageView:0x10aa05f10.left + 10>",
"<MASLayoutConstraint:0x283e665e0 UILabel:0x10aa0bfa0.right <= SDAnimatedImageView:0x10aa05f10.right>",
"<NSAutoresizingMaskLayoutConstraint:0x283952030 UIView:0x10aa0a4a0.width == 0>"
)
scrollView、HeaderView均使用frame约束,SliderView、CollectionView、Cell、RankRadioIconView、(label、image)都是用Masonry约束,UIView:0x10aa0a4a0.width == 0
该view为Cell的contentView。起初怀疑是frame、Masonry一同使用姿势不对导致的,排查半天没发现异常使用。最终在看到:
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
在VC的ViewDidLoad中用frame布局完scrollView、HeaderView后传入collectionView数据源调用了该行代码,换成[self.collectionView reloadData];
后就没有警告了。
思考
reloadData
和reloadSections
的刷新方式肯定不同,在reloadData
后的 collectionView:cellForItemAtIndexPath
中cell.frame不为0,而reloadSections
后cell.frame为0,导致Masonry告警。(cell采用注册方式创建[collectionView registerClass:[Cell class] forCellWithReuseIdentifier:@"CellID"];)
网友评论