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

时间:2019-03-18 15:02:26

标签: ios swift uicollectionview

在调用indexpath.sectionrow时,是否有什么方法只能在UICollectionView viewDidApper()之间排除viewWillAppear()

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

在这里,我只想在一个indexpath.section到另一个indexpath.section之间滚动,并希望在滚动时避开indexpath.row节。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

要从一个IndexPath.section滚动到另一个items,我仅在需要时使用collectionView中的boolean将新的collectionView.reloadData()添加到 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { if tabSelected { return 2 } else { return 1 } }

{{1}}

对我来说很完美;)