컬렉션보기를 UIView에서 래핑 할 수 있습니다. 컬렉션보기에는 래퍼보기가있는 동일한 경계가 있습니다. 또한 콜렉션보기 데이터 소스가 변경되어 랩퍼보기 경계도 변경됩니다. 래퍼보기 intrinsicContentSize
메서드를 collectionView.collectionViewLayout.collectionViewContentSize
으로 구현했으며 컬렉션보기 레이아웃은 UICollectionViewFlowLayout
의 하위 클래스이고 UICollectionView의 셀 또한 intrinsicContentSize
메서드를 구현하지만 래퍼보기는 컬렉션보기 콘텐츠 크기로 프레임을 업데이트하지 않았습니다. collectionViewContentSize
은 항상 CGRectZero
입니다. 내가 UICollectionView 래퍼 뷰 프레임 업데이트
[self.layout invalidateLayout];
[self.collectionView reloadData];
[self.collectionView layoutIfNeeded];
을 시도했지만 작동하지 않았다, 내가
collectionView.collectionViewLayout.collectionViewContentSize
와 래퍼보기 프레임을 업데이트하려면 어떻게해야합니까. 당신이 자동 레이아웃을 사용하는 것처럼
ZXCollectionViewWrapperView *wrapperView = [[ZXCollectionViewWrapperView alloc] init];
[self.view addSubview:wrapperView];
[wrapperView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.view);
}];
self.wrapperView = wrapperView;
/// wrapper view size
- (CGSize)intrinsicContentSize {
return self.collectionView.collectionViewLayout.collectionViewContentSize;
}
ZXCollectionViewAlignedLayout *layout = [[ZXCollectionViewAlignedLayout alloc] init];
self.layout = layout;
ZXCollectionView *collectionView = [[ZXCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
collectionView.dataSource = self;
collectionView.delegate = self;
collectionView.backgroundColor = [UIColor lightGrayColor];
[self addSubview:collectionView];
[collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
self.collectionView = collectionView;
[self.collectionView zx_registerCellClass:[ZXCommendCell class]];
self.dataSource = dataSource;
[self.collectionView reloadData];
[self.collectionView layoutIfNeeded];
래퍼보기가있는 UILabel처럼 UICollectionView contentSize에 의해 래퍼보기 조정 크기가 필요합니다. (래퍼보기가있는 UIlLabel이 작동했습니다. – jacinzhang
컬렉션보기에서는 스크롤보기이므로 할 수 없습니다. – dduyduong