繁体   English   中英

如何仅在UICollectionView中的indexpath.section之间排除滚动indexpath.row

[英]How can only scroll only between Indexpath.section exclude indexpath.row in UICollectionView

有什么方法只能在UICollectionView indexpath.section indexpath.section viewDidApper()viewWillAppear()时在排除row之间滚动吗?

例如

collectionView.scrollToItem(at: IndexPath(row: 0, section: anySectionNumber), at: .centeredHorizontally, animated: false)

在这里,我只想在一个indexpath.section到另一个indexpath.section之间滚动,并想避免滚动时出现indexpath.row部分。

如果您没有节头,则您提供的解决方案(滚动到节中的第0行)是正确的。 相反,如果要滚动到标题,则标题会稍微复杂一点,因为没有用于该标题的方法。 有一种方法可以滚动到scrollview中的任意矩形: scrollRectToVisible(_:animated :) 您可以通过调用layoutAttributesForSupplementaryView(ofKind:at :)并使用返回属性的框架来获取标题的矩形。 (框架在collectionview的坐标系中)。

为了从一个IndexPath.section滚动到另一个IndexPath.section ,我仅在需要时使用collectionView.reloadData()boolean将新items添加到collectionView

 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
   {
        if tabSelected
        {
           return 2
        }

        else
        {
          return 1
        }
}

这对我来说是完美的;)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM