我想要一个水平滚动集合视图在两边(左和右)滚动,现在它只在右方向连续滚动,如何在左侧实现?
let itemcount = array?.count ?? 0
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView == DemoCollectionView {
let offSet = scrollView.contentOffset.x
let width = scrollView.frame.width
let horizontalCenter = width / 2
let currentPage = Int(offSet + horizontalCenter) / Int(width)
if currentPage >= itemCount / 2 {
itemCount += array?.count ?? 0
DemoCollectionView.reloadData()
}
}
}发布于 2020-07-15 12:26:22
您可以使用"scrollToItemAtIndexPath“方法来完成它。可以从滚动视图委托方法中获得滑动方向。
从右向左滚动
collectionView?.scrollToItemAtIndexPath(NSIndexPath(forItem: dataArray.count - 1, inSection: 0), atScrollPosition: .Right, animated: false)滚动器从左向右滚动
collectionView?.scrollToItemAtIndexPath(NSIndexPath(forItem: 0, inSection: 0), atScrollPosition: .left, animated: false)您还可以在集合视图上应用转换以获得类似的结果。
https://stackoverflow.com/questions/62914521
复制相似问题