I have a problem in iOS 10 (only) with my UICollectionView. My VC has a UICollectionView about 1/3 down from the top. The UICollectionView shows two rows of buttons in six columns. The layout works perfect in iOS 11. But in iOS 10 only one row of buttons show. I've inspected the frame that I am assigning to the UICollectionView and, of course, it's the same in both iOS 10 and iOS 11. There's exactly enough space to fit the two rows. The problem happens in both the simulator and device. I'm using Xcode 9.4.1 and Swift 4.1.
Here's the method that prepares the layout.
private var theLayout: UICollectionViewFlowLayout {
return (buttonsView.collectionViewLayout as? UICollectionViewFlowLayout)!
}
func prepareLayout(for frame: CGRect, and numberOfColumns: Int, animated: Bool = false) {
let size = CGSize(width: frame.size.width / (CGFloat(6), height: frame.size.height / CGFloat(2))
// Continue only if a change is detected.
guard buttonsView.frame != frame, theLayout.itemSize != size else { return }
// Closure to be run with animation or no animation.
let updateLayout = {
self.theLayout.sectionInset = .zero
self.theLayout.minimumInteritemSpacing = 0
self.theLayout.minimumLineSpacing = 0
self.theLayout.itemSize = size // CGSize(width: size.width, height: size.height)
self.buttonsView.frame = frame
self.theLayout.invalidateLayout()
}
animated ? UIView.standardAnimations { updateLayout() } : updateLayout()
}
The UICollectionView is initialized like this:
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.itemSize = CGSize(width: 70, height: 20)
buttonsView = UICollectionView(frame: .zero, collectionViewLayout: layout)
According to the AppStore, 14% of devices are still using iOS 10!
I even tried using UICollectionViewDelegateFlowLayout which shouldn't be necessary because all my itms are the same size and I have the same problem.
Anybody know what's going on?