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 329 forks source link

同一个界面有两个collectionView的时候回出错 #89

Open FzyJanm opened 4 years ago

FzyJanm commented 4 years ago

在collectionView中添加这个控件的时候回出现 代理错乱的情况 希望作者及时发现调整

isdotjim commented 4 years ago

搭个车... 想邀请Repo作者来w3c.group创建项目的对应小组。w3c.group是类似知识星球的社群工具,小组可设置为付费且有赞助功能,同时也是一个区块链主导的创作者社区。这是相关介绍: http://t.cn/Ai1vLcCU http://t.cn/Ai1vLcCG http://t.cn/Ai1vLcCA

12207480 commented 4 years ago

有代码 或者 截图吗

JianWenXie commented 4 years ago

我也是遇到了同样的情况 // // HomeViewCtrl.swift // VKIntlProperty // // Created by fox on 2021/2/3. // Copyright © 2019 com.vk.TestP. All rights reserved. //

import UIKit

class VKHomeViewCtrl: VKBaseViewCtrl {

var collectionView:UICollectionView!
var dataArr:Array<String>!
override func viewDidLoad() {
    super.viewDidLoad()
    dataArr = ["会所预定","物业公告","我的订单","工单报事","分类标题","分类标题"]
    setupUI()

}

func setupUI() {
    /// 左地址选择
    let leftView = UIView.init()
    let btn = UIButton.init(type: .custom)
    btn.titleOfNormal = "金色家园1栋"
    btn.imageOfNormal = UIImage.init(named: "nav_icon_ place")
    btn.titleColorOfNormal = UIColorFromHex(hexValue: Color_CommNavTitleBlack)
    btn.frame = CGRect.init(x: 0, y: 0, width: 140, height: 40)
    btn.layoutButton(with: .left, imageTitleSpace: 8)
    leftView.addSubview(btn)
    leftView.frame = CGRect.init(x: 0, y: 0, width: 140, height: 40)
    navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: leftView)

    let rightBtn = UIButton()
    rightBtn.layoutButton(with: .right, imageTitleSpace: 10)
    rightBtn.imageOfNormal = UIImage.init(named: "nav_btn_news_default")
    rightBtn.frame = CGRect.init(x: 0, y: 0, width: 40, height: 40)
    rightBtn.addTarget(self, action: #selector(pushMessageListCtr), for: .touchUpInside)
    navigationItem.rightBarButtonItem = UIBarButtonItem.init(customView: rightBtn)

   let layout = UICollectionViewFlowLayout.init()
    layout.scrollDirection = .vertical
    layout.minimumLineSpacing = 0
    layout.minimumInteritemSpacing = 0
    /// 如果设置家最小间距 直接给宽度会问题
    layout.itemSize = CGSize.init(width:(ScreenWidth - 0 )/3, height: (ScreenWidth-0)/3)
    collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: layout)
    collectionView.dataSource = self
    collectionView.delegate = self
    collectionView.backgroundColor = UIColor.white
    collectionView.register(VKHomeCollectionCell.classForCoder(), forCellWithReuseIdentifier: "cellID")

    collectionView.register(UICollectionReusableView.classForCoder(), forSupplementaryViewOfKind:
        UICollectionView.elementKindSectionHeader, withReuseIdentifier: "headerView")
    view.addSubview(collectionView)
}

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    collectionView.frame = view.bounds
}

@objc func pushMessageListCtr() {
    let vc = VKMessageListCtrl.init()
    navigationController?.pushViewController(vc, animated: true)
}

}

//MARK: - UICollectionViewDataSource,UICollectionViewDelegate extension VKHomeViewCtrl: UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UICollectionViewDelegate{ func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return dataArr.count }

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellID", for: indexPath)as! VKHomeCollectionCell

    cell.titleLabel.text = dataArr[indexPath.row]
    return cell
}

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
    let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "headerView", for: indexPath)

   let pageView = TYCyclePagerView()
    pageView.isInfiniteLoop = true
    pageView.dataSource = self
    pageView.delegate = self
    pageView.register(VKHomeCarouselCell.classForCoder(), forCellWithReuseIdentifier: "VKHomeCarouselCell")
    pageView.frame = CGRect.init(x: 16, y: 0, width: ScreenWidth - 32, height: 172)
    view.addSubview(pageView)
    //这里放轮播图
    return view
}

func collectionView(_ collectionView: UICollectionView,
                    layout collectionViewLayout: UICollectionViewLayout,
                    referenceSizeForHeaderInSection section: Int) -> CGSize {

    return CGSize(width: collectionView.bounds.width, height: 171
    )
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    var vc:UIViewController!
    switch indexPath.row {
    case 0:
        vc = VKClubListCtrl.init()
        break
    case 1:
        vc = VKNotificationListCtrl.init()
        break
    case 2:
        vc = VKOrderListCtrl.init()
         break
    case 3:
        // http://sqyypttest.vankeservice.com:9000/p/web/serviceRequest
        vc = VKRepairOrderCtrl.init(weburl: "http://sqyypttest.vankeservice.com:9000/p/web/serviceRequest")
        break
    default:
        vc = nil
        break
    }
    if ((vc) != nil) {
        navigationController?.pushViewController(vc, animated: true)
    }
}

}

extension VKHomeViewCtrl:TYCyclePagerViewDataSource,TYCyclePagerViewDelegate{ func pagerViewTransformLayout(_ pagerViewTransformLayout: TYCyclePagerTransformLayout, initializeTransform attributes: UICollectionViewLayoutAttributes) { Log(message: "呵呵呵") }

func pagerViewTransformLayout(_ pagerViewTransformLayout: TYCyclePagerTransformLayout, applyTransformTo attributes: UICollectionViewLayoutAttributes) {
    Log(message: "哈哈哈")
}

func numberOfItems(in pageView: TYCyclePagerView) -> Int {
    return 1
}

func pagerView(_ pagerView: TYCyclePagerView, cellForItemAt index: Int) -> UICollectionViewCell {
    let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "VKHomeCarouselCell", for: index)as!VKHomeCarouselCell
    cell.lab.text = String.init(format: "哈哈哈%d", index)
    return cell
}

func layout(for pageView: TYCyclePagerView) -> TYCyclePagerViewLayout {
    let layout = TYCyclePagerViewLayout.init()
    layout.itemSize = CGSize.init(width: ScreenWidth, height: 172 * kScreen)
    layout.itemHorizontalCenter = true
    return layout
}

}