TYCyclePagerView icon indicating copy to clipboard operation
TYCyclePagerView copied to clipboard

Swift使用SnapKit布局PageControl的Bug

Open trylee opened this issue 5 years ago • 1 comments

在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)

trylee avatar Dec 25 '19 06:12 trylee

+1

tounaobun avatar Jul 03 '20 14:07 tounaobun