Reset scroll on UICollectionView

前端 未结 9 1189
太阳男子
太阳男子 2021-01-30 05:25

I have a horizontal UICollectionView which works fine and scrolls. When I tap an item I update my data and call reloadData. This works and the new data

9条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-30 05:37

    To deal with an UINavigationController and a transparent navigation bar, I had to calculate the extra top offset to perfectly match the position of the first element.

    Swift 1.1 code:

         let topOffest = CGPointMake(0, -(self.collectionView?.contentInset.top ?? O))
         self.collectionView?.setContentOffset(topOffest, animated: true)
    

    Cheers!

提交回复
热议问题