Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wangmeng-12138 opened this issue Sep 7, 2023 · 0 comments

Comments

@wangmeng-12138
Copy link

wangmeng-12138 commented Sep 7, 2023

如题,设置了.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 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant