implementing UIScrollView nested inside a UICollectionView - Laggy performance on iOS 17
I'm writing unit tests and I tried several approaches but none seem to work. I've searched everywhere and can't find a clear answer. I'm working on a project and hit a roadblock. I'm working on a project and hit a roadblock. Hey everyone, I'm running into an issue that's driving me crazy. I'm working on an iOS app where I need to implement a vertical `UICollectionView` containing multiple `UICollectionViewCell` items, each of which has a `UIScrollView` for horizontal scrolling of images. The question arises when I try to scroll vertically through the collection view; it feels laggy and unresponsive, especially with more than 10 cells. I've tried optimizing the layout by setting appropriate constraints and reusing cells properly, but the performance is still subpar. Hereโs a simplified version of the code Iโm using: ```swift class MyCollectionViewController: UICollectionViewController { override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 20 // For example } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyCell", for: indexPath) as! MyCustomCell cell.configure(with: images[indexPath.row]) return cell } } class MyCustomCell: UICollectionViewCell { @IBOutlet weak var scrollView: UIScrollView! func configure(with images: [UIImage]) { // Add image views to scrollView } } ``` I also attempted to adjust the `contentSize` of the `UIScrollView` manually based on the number of images, but it didnโt help much. Iโm utilizing `UICollectionViewFlowLayout`, and I tried setting `estimatedItemSize` to see if that would help, but it hasn't improved the scrolling experience. When I profile the app with Instruments, I see that there are a lot of layout pass calls when I scroll, which seems to indicate that my layout is not optimal. I suspect that the nested scroll views might be causing the main collection view to struggle with the layout calculations. Has anyone run into similar issues or have any suggestions for improving the performance of a nested `UIScrollView` within a `UICollectionView`? Any tips on layout or configuration changes would be greatly appreciated! Is there a better approach? Any help would be greatly appreciated! My development environment is Debian. Cheers for any assistance! Is this even possible? The stack includes Swift and several other technologies.