[英]How to prevent scrolling left to right of collection view in horizontal scroll direction?
[英]how to make a collection view to scroll horizontally having infinite scroll in both directions left, as well as right in iOS swift
我想要一個水平滾動的集合視圖在兩側(左右)滾動,現在它只在右方向連續滾動,如何在左側實現?
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()
}
}
}
您可以使用“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)
您還可以在集合視圖上應用轉換以獲得相似。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.