簡體   English   中英

如何將單元格邊界與超級視圖的邊界匹配?

[英]How do I match cell boundary to bounds of superview?

我有一個UICollectionViewController和一個UICollectionViewCell

我想有從的邊界前緣和后空間UICollectionViewCell到的范圍UICollectionViewController所以當方向改變我的細胞將調整到新的水平范圍。

通常如何做?

編輯:我使用estimatedItemSize計算尺寸在我UICollectionViewFlowLayout如果這有助於。

好的,基本上解決了。 因為我使用的是iOS 8的自動單元格調整大小(如estimatedItemSize ),所以我需要在單元格中實現preferredLayoutAttributesFittingAttributes 這是我的實現:

- (UICollectionViewLayoutAttributes * _Nonnull)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes * _Nonnull)layoutAttributes {
    UICollectionViewLayoutAttributes *attr = [layoutAttributes copy];
    CGRect newFrame = attr.frame;
    self.frame = newFrame;

    [self setNeedsLayout];
    [self layoutIfNeeded];

    CGFloat desiredHeight = [self.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    newFrame.size.height = desiredHeight;
    newFrame.size.width = _containerWidth - 20;
    attr.frame = newFrame;
    return attr;
}

_containerWidth是我單元格中的一個屬性。 我把我的手機的_containerWidthcellForItemAtIndexPath在我的CollectionView。

盡管可能有一種更優雅的方法,但我只是在旋轉過程中在collectionview上調用reloadData

我暫時放棄了調整屏幕旋轉單元格的大小,因為它有很多問題,但是對於這個問題,這已經足夠了。 如果有人找到更好的解決方案,我將保留這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM