[英]Ambiguous use of subscript using [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.