查了很多方法都不太行
最后在一个scorllView的协议上看到了希望,实验之后成功了。
var page = 0
var oldX = 0.0
//MARK: 控制每次只能滑动一个 减少滑动距离
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
//print("targetContentOffset.pointee.x == ",targetContentOffset.pointee.x)
if oldX < targetContentOffset.pointee.x {
//右滑
if self.page >= self.imageArr.count {
page = self.imageArr.count - 1
}else{
page = page + 1
}
targetContentOffset.pointee.x = CGFloat(page) * (kScreenWidth - 70 + 20)
} else {
//左滑
if self.page > 1 {
page = page - 1
}else{
page = 0
}
//kScreenWidth - 70 + 20 item 大小 加上 边界
targetContentOffset.pointee.x = CGFloat(page) * (kScreenWidth - 70 + 20)
}
oldX = targetContentOffset.pointee.x
}