记录collectionView的scrollToItem方法无效

需要注意的点:
1.如果是横向滑动的,scrollPosition的值设为.centeredHorizontally
2.当collectionView显示它的subView之前调用scrollToItemAtIndexPath: atScrollPosition:
Animated方法,是不会执行的。
可以代码写在layoutSubViews中或者延时就能执行

代码记录

 Date.jx_after {
            self.scorllToday()
  }
 func scorllToday() {
   if let day = selModel?.year_month_day,let idx = dataSource.firstIndex(where: {$0.year_month_day.isEque(day: day)}){
            let indexPath = IndexPath(row: idx, section: 0)
            collectionView.isPagingEnabled = false
            collectionView.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true)
            collectionView.isPagingEnabled = true
        }
 }

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注