0

when I am adding UICollectionViewFlowLayout file with collection view. collectionViewCell height is not increasing according to the collection view. it takes spacing from the top and bottom:

image path

- (void)awakeFromNib
{
    [super awakeFromNib];
    self.itemSize = CGSizeMake((self.collectionView.frame.size.width/2)+100,self.collectionView.frame.size.height );

    //self.minimumInteritemSpacing = 10.0;
    self.minimumLineSpacing = 10.0;
    self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.sectionInset = UIEdgeInsetsMake(0, 30.0, 0, 30.0);
}

- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity {

    NSInteger itemsCount = [self.collectionView.dataSource collectionView:self.collectionView numberOfItemsInSection:0];

    // Imitating paging behaviour
    //  previous offset and scroll direction
    if ((self.previousOffset > self.collectionView.contentOffset.x) && (velocity.x < 0.0f)) {
        self.currentPage = MAX(self.currentPage - 1, 0);

    } else if ((self.previousOffset < self.collectionView.contentOffset.x) && (velocity.x > 0.0f)) {
        self.currentPage = MIN(self.currentPage + 1, itemsCount - 1);
    }

    // Update offset by using item size + spacing
    CGFloat updatedOffset = (self.itemSize.width + 5) * self.currentPage;
    self.previousOffset = updatedOffset;

    return CGPointMake(updatedOffset, proposedContentOffset.y);
}

i have created sub class of UICollectionViewLayout.

  • "UICollectionViewFlowLayout file with collection view" ? What's your code? Did you set the delegate? – Larme Feb 05 '18 at 13:07
  • 1
    I guess you are using Autolayout. So in `awakeFromNib`, the `self.collectionView.frame` is the frame of the collectionView inside the xib, but if the xib have been "resized" because of autolayout, then your measure is wrong (outdated). Instead, be delegate, and use `collectionView:layout:sizeForItemAtIndexPath:` – Larme Feb 05 '18 at 14:08
  • Thank you.. it helpful for me. – babita singh Feb 06 '18 at 05:19

0 Answers0