12207480 / TYCyclePagerView

a simple and usefull cycle pager view ,and auto scroll banner view(轮播图) ,include pageControl for iOS,support Objective-C and swift
MIT License
1.79k stars 327 forks source link

Swift使用SnapKit布局PageControl的Bug #94

Open trylee opened 4 years ago

trylee commented 4 years ago

在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)
tounaobun commented 4 years ago

+1