diff --git a/IBPCollectionViewCompositionalLayout.podspec b/IBPCollectionViewCompositionalLayout.podspec index 0cdf32b..81db344 100644 --- a/IBPCollectionViewCompositionalLayout.podspec +++ b/IBPCollectionViewCompositionalLayout.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'IBPCollectionViewCompositionalLayout' - s.version = '0.6.7' + s.version = '0.6.9' s.summary = 'Backport of UICollectionViewCompositionalLayout to earlier iOS 12.' s.description = <<-DESC A new UICollectionViewCompositionalLayout class has been added to UIKit to make it incredibly easier to create custom complex collection view layout. diff --git a/Sources/IBPCollectionViewCompositionalLayout/IBPUICollectionViewCompositionalLayout.m b/Sources/IBPCollectionViewCompositionalLayout/IBPUICollectionViewCompositionalLayout.m index 12667d1..a060d7f 100644 --- a/Sources/IBPCollectionViewCompositionalLayout/IBPUICollectionViewCompositionalLayout.m +++ b/Sources/IBPCollectionViewCompositionalLayout/IBPUICollectionViewCompositionalLayout.m @@ -136,7 +136,7 @@ - (void)prepareLayout { return; } - if (!self.collectionViewDelegate && collectionView.delegate != self) { + if (collectionView.collectionViewLayout == self && !self.collectionViewDelegate && collectionView.delegate != self) { self.collectionViewDelegate = collectionView.delegate; collectionView.delegate = self; } @@ -145,7 +145,7 @@ - (void)prepareLayout { UIEdgeInsets collectionContentInset = UIEdgeInsetsZero; if (@available(iOS 11.0, *)) { - if ([collectionView respondsToSelector:@selector(safeAreaInsets)]) { + if ([collectionView respondsToSelector:@selector(safeAreaInsets)] && collectionView.contentInsetAdjustmentBehavior != UIScrollViewContentInsetAdjustmentNever) { collectionContentInset = collectionView.safeAreaInsets; } } @@ -527,7 +527,51 @@ - (UICollectionViewLayoutAttributes *)prepareLayoutForBoundaryItem:(IBPNSCollect withIndexPath:indexPath]; IBPNSCollectionLayoutContainer *itemContainer = [[IBPNSCollectionLayoutContainer alloc] initWithContentSize:containerFrame.size contentInsets:IBPNSDirectionalEdgeInsetsZero]; - CGSize itemSize = [boundaryItem.layoutSize effectiveSizeForContainer:itemContainer]; + IBPNSCollectionLayoutSize *layoutSize = boundaryItem.layoutSize; + CGSize itemSize; + + if (layoutSize.heightDimension.isEstimated || layoutSize.widthDimension.isEstimated) { + UICollectionReusableView *view = [self.collectionView.dataSource collectionView:self.collectionView + viewForSupplementaryElementOfKind:boundaryItem.elementKind + atIndexPath:indexPath]; + + if (view) { + CGSize containerSize = self.collectionViewContentSize; + + if (!layoutSize.widthDimension.isEstimated) { + containerSize.width = CGRectGetWidth(containerFrame); + } + if (!layoutSize.heightDimension.isEstimated) { + containerSize.height = CGRectGetHeight(containerFrame); + } + + CGFloat containerWidth = containerSize.width; + CGFloat containerHeight = containerSize.height; + + CGRect viewFrame = view.frame; + viewFrame.size = containerSize; + view.frame = viewFrame; + [view setNeedsLayout]; + [view layoutIfNeeded]; + + CGSize fitSize; + if (layoutSize.widthDimension.isEstimated) { + fitSize = [view systemLayoutSizeFittingSize:containerSize + withHorizontalFittingPriority:UILayoutPriorityFittingSizeLevel + verticalFittingPriority:UILayoutPriorityRequired]; + fitSize.height = containerHeight; + } else { + fitSize = [view systemLayoutSizeFittingSize:containerSize + withHorizontalFittingPriority:UILayoutPriorityRequired + verticalFittingPriority:UILayoutPriorityFittingSizeLevel]; + fitSize.width = containerWidth; + } + + itemSize = fitSize; + } + } else { + itemSize = [boundaryItem.layoutSize effectiveSizeForContainer:itemContainer]; + } IBPNSCollectionLayoutAnchor *containerAnchor; switch (boundaryItem.alignment) { @@ -846,7 +890,7 @@ - (void)scrollViewDidChangeAdjustedContentInset:(UIScrollView *)scrollView API_A } - (BOOL)respondsToSelector:(SEL)aSelector { - return [self.collectionViewDelegate respondsToSelector:aSelector] || [super respondsToSelector:aSelector]; + return [self.collectionViewDelegate respondsToSelector:aSelector] || [UICollectionViewLayout instancesRespondToSelector:aSelector]; } - (void)forwardInvocation:(NSInvocation *)anInvocation { diff --git a/Sources/Info.plist b/Sources/Info.plist index a7b18e1..65609fa 100644 --- a/Sources/Info.plist +++ b/Sources/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.6.7 + 0.6.9 CFBundleVersion $(CURRENT_PROJECT_VERSION)