在调用indexpath.section
或row
时,是否有什么方法只能在UICollectionView viewDidApper()
之间排除viewWillAppear()
?
例如collectionView.scrollToItem(at: IndexPath(row: 0, section: anySectionNumber), at: .centeredHorizontally, animated: false)
在这里,我只想在一个indexpath.section
到另一个indexpath.section
之间滚动,并希望在滚动时避开indexpath.row
节。
答案 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}}
对我来说很完美;)