コレクションビューは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