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

Swift使用SnapKit布局PageControl的Bug #94

Open
trylee opened this issue Dec 25, 2019 · 1 comment
Open

Swift使用SnapKit布局PageControl的Bug #94

trylee opened this issue Dec 25, 2019 · 1 comment

Comments

@trylee
Copy link

trylee commented Dec 25, 2019

在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
Copy link

+1

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

2 participants