FSPagerView icon indicating copy to clipboard operation
FSPagerView copied to clipboard

为什么在cellForItemAt方法里 打印index是 滚动两张图片直接执行两次啊?

Open wangmeng-12138 opened this issue 9 months ago • 0 comments

如题,设置了.automaticSlidingInterval = 3,.isInfinite = true,然在想在cellForItemAt里同步pageControl,但不是滚动结束执行一次cellForItemAt,而是每滚动两次执行两次cellForItemAt。是我使用的姿势不对吗?

lazy var pagerView: FSPagerView = { let height = kAutoWidth(230) let pagerView = FSPagerView(frame: CGRect(x: 0, y: 0, width: self.width, height: height)) pagerView.dataSource = self pagerView.delegate = self pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell") pagerView.automaticSlidingInterval = 3 pagerView.isInfinite = true pagerView.transformer = FSPagerViewTransformer(type: .crossFading) return pagerView }()

lazy var pageControl: FSPageControl = { let pageControl = FSPageControl(frame: CGRect(x: 0, y: self.pagerView.height - 40, width: self.pagerView.width, height: 40)) pageControl.numberOfPages = self.imgUrlArr.count pageControl.setFillColor(.yellow, for: .normal) pageControl.setFillColor(.green, for: .selected) pageControl.contentHorizontalAlignment = .center return pageControl }()

let imgUrlArr: [String] = ["https://img2.baidu.com/it/u=934832623,1995325879&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500","https://img1.baidu.com/it/u=4040579388,2418117984&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800","https://img1.baidu.com/it/u=2998038743,532699456&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800","https://img2.baidu.com/it/u=777438846,3968705129&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800","https://img11.kcimg.cn/officialpic/0/17/jucno.jpg%21800","https://img0.baidu.com/it/u=2781643291,4205855787&fm=253&fmt=auto&app=138&f=PNG?w=769&h=500"]

func numberOfItems(in pagerView: FSPagerView) -> Int { imgUrlArr.count } func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell { let urlStr = self.imgUrlArr[index] let imgUrl = URL(string: urlStr) let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) cell.imageView?.kf.setImage(with: imgUrl) print("\(index)") return cell }

wangmeng-12138 avatar Sep 07 '23 09:09 wangmeng-12138