TYCyclePagerView
TYCyclePagerView copied to clipboard
Swift使用SnapKit布局PageControl的Bug
在Swift中使用TYCyclePagerView,如果使用SnapKit库布局PageControl,会导致界面错乱,不调用layoutForPagerView方法,且视图查看会有多个Cell,具体代码如下:
let cycleView = TYCyclePagerView()
cycleView.dataSource = self
cycleView.isInfiniteLoop = true
cycleView.autoScrollInterval = 3
cycleView.register(YoungHomePageCycleCell.self, forCellWithReuseIdentifier: "YoungHomePageCycleCell")
view.addSubview(cycleView)
cycleView.snp.makeConstraints { (make) in
make.left.right.equalToSuperview()
make.top.equalTo(view.safeAreaLayoutGuide)
make.height.equalTo(cycleView.snp.width).multipliedBy(0.38)
}
let pageControl = TYPageControl()
pageControl.numberOfPages = images.count
pageControl.pageIndicatorTintColor = AppColor.basicColor
pageControl.currentPageIndicatorTintColor = AppColor.themeColor
pageControl.pageIndicatorSize = CGSize(width: 8, height: 8)
pageControl.currentPageIndicatorSize = CGSize(width: 15, height: 8)
cycleView.addSubview(pageControl)
pageControl.snp.makeConstraints { (make) in
make.centerX.bottom.equalToSuperview()
make.size.equalTo(CGSize(width: 100, height: 20))
}
如果使用Frame布局pageControl就不存在该问题,且layoutForPagerView数据源方法正常调用,代码如下:
let cycleView = TYCyclePagerView()
cycleView.dataSource = self
cycleView.isInfiniteLoop = true
cycleView.autoScrollInterval = 3
cycleView.register(YoungHomePageCycleCell.self, forCellWithReuseIdentifier: "YoungHomePageCycleCell")
view.addSubview(cycleView)
cycleView.snp.makeConstraints { (make) in
make.left.right.equalToSuperview()
make.top.equalTo(view.safeAreaLayoutGuide)
make.height.equalTo(cycleView.snp.width).multipliedBy(0.38)
}
let pageControl = TYPageControl(frame: CGRect(x: 0, y: 0, width: 100, height: 20))
pageControl.numberOfPages = images.count
pageControl.pageIndicatorTintColor = AppColor.basicColor
pageControl.currentPageIndicatorTintColor = AppColor.themeColor
pageControl.pageIndicatorSize = CGSize(width: 8, height: 8)
pageControl.currentPageIndicatorSize = CGSize(width: 15, height: 8)
cycleView.addSubview(pageControl)
+1