水平设置时UICollectionView滚动的自然方向是从左到右。有没有办法扭转这种局面?越简单越好。
我不确定你的意思 - 如果你将滚动设置为水平,它会向右和向右滚动。如果您希望它从右侧启动它,您可以使用此方法:
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.theData.count - 1 inSection:0] atScrollPosition:UICollectionViewScrollPositionRight animated:NO];
这假定您有1个部分,填充集合视图的数组称为theData。
同样的事情对于swift:
collectionView?.scrollToItemAtIndexPath(NSIndexPath(forItem: theData.count - 1, inSection: 0), atScrollPosition: .Right, animated: false)
CellForItemAt集合视图函数中的Swift4解决方案
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = categoryBook.dequeueReusableCell(withReuseIdentifier: "HomeCategoryCell", for: indexPath) as! HomeCategoryCell
collectionView.transform = CGAffineTransform(scaleX:-1,y: 1);
cell.transform = CGAffineTransform(scaleX:-1,y: 1);
}
但是这个解决方案在某些情况下确实可以使用colletcion视图scrollToItem方法,你可以在重新加载数据后实现它。
t work properly if it dosen