UICollectionViewFlowLayout estimatedItemSize does not work properly with iOS12 though it works fine with iOS 11.*

In my case, I solved this by explicitly adding the following constraints to the cell’s contentView. class Cell: UICollectionViewCell { // … override func awakeFromNib() { super.awakeFromNib() // Addresses a separate issue and prevent auto layout warnings due to the temporary width constraint in the xib. contentView.translatesAutoresizingMaskIntoConstraints = false // Code below is needed to … Read more

Warning: UICollectionViewFlowLayout has cached frame mismatch for index path ‘abc’

This is likely occurring because the flow layout “xyz” is modifying attributes returned by UICollectionViewFlowLayout without copying them And sure enough, that’s just what you are doing: private override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? { let attributes = super.layoutAttributesForItemAtIndexPath(indexPath) let distance = CGRectGetMidX(attributes!.frame) – self.midX; var transform = CATransform3DIdentity; transform = CATransform3DTranslate(transform, -distance, 0, -self.width); … Read more

UICollectionView with a sticky header

Simplest solution for iOS 9 + as it doesn’t need of writing subclass of UICollectionViewFlowLayout. In viewDidLoad of viewController with collectionView use following code: let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout // casting is required because UICollectionViewLayout doesn’t offer header pin. Its feature of UICollectionViewFlowLayout layout?.sectionHeadersPinToVisibleBounds = true

UICollectionView Custom Cell to fill width In Swift

You need to do this programatically. Implement UICollectionViewDelegateFlowLayout in your view controller and provide the size in collectionView:layout:sizeForItemAtIndexPath: func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let kWhateverHeightYouWant = 100 return CGSizeMake(collectionView.bounds.size.width, CGFloat(kWhateverHeightYouWant)) } You will also want to call collectionView.collectionViewLayout.invalidateLayout() inside your view controller’s viewWillLayoutSubviews() so that when the … Read more

Custom animation when switching from one UICollectionViewLayout to another?

#define degreesToRadians(x) (M_PI * (x) / 180.0) UICollectionView *collectionView = self.viewController.collectionView; HorizontalCollectionViewLayout *horizontalLayout = [HorizontalCollectionViewLayout new]; NSTimeInterval duration = 2; [collectionView.visibleCells enumerateObjectsUsingBlock:^(UICollectionViewCell *cell, NSUInteger index, BOOL *stop) { CABasicAnimation *rotationAnimation; rotationAnimation = [CABasicAnimation animationWithKeyPath:@”transform.rotation”]; rotationAnimation.toValue = @(degreesToRadians(360)); rotationAnimation.duration = duration; rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; [cell.layer addAnimation:rotationAnimation forKey:@”rotationAnimation”]; }]; [UIView animateWithDuration:duration animations:^ { collectionView.collectionViewLayout = horizontalLayout; … Read more

UICollectionView wrong contentSize on first load, correct after that

So I was seeing a similar issue where contentSize width was always zero. The simple answer is…there is probably no content in the collectionView yet. That was why it’s content size is zero. I was also noticing that sometimes after calling invalidateLayout on my UICollectionView, I was seeing that self.collectionView.collectionViewLayout.collectionViewContentSize was not the same as … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)