I have one collectionview with compositional layout, section 0 is a horizontal scrollable one with paging enabled (red circle on the picture).
So I use collectionView.scrollToItem(at: indexPath, animated: true) on collection view with a Timer to auto scroll section 0. But whenever the scroll happened, it automatically focus on section 0.
Is there any way to allow auto scroll on section 0, but prevent this section get focus while user maybe browse items further down of the collection view. Currently whenever auto scroll happen, it scroll onto the very top as well.
Here is the code fot setting up the compositional layout for collection view. section 0 is horizontal scrollable.
let compLayout = UICollectionViewCompositionalLayout { (sectionNumer, env) -> NSCollectionLayoutSection? in
if sectionNumer == 0 {
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1)))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .estimated(280)), subitems: [item])
let section = NSCollectionLayoutSection(group: group)
section.orthogonalScrollingBehavior = .paging
return section
} else {
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(0.5), heightDimension: .absolute(200)))
item.contentInsets.trailing = 8
item.contentInsets.bottom = 8
let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .estimated(500)), subitems: [item])
group.contentInsets.leading = 8
let section = NSCollectionLayoutSection(group: group)
return section
}
}
Apologise if this has been answered, but I didn't find it. Appreciated for any help.