仿iOS系统相册浏览样式

本文介绍如何使用Swift实现一个类似iOS系统相册的浏览样式,包括两个UICollectionView的联动滚动,左右滑动及上下同步的效果。通过自定义TopCollectionView和BottomCollectionView类,实现了水平滚动和页面切换选中效果,同时详细展示了代码实现过程。
摘要由CSDN通过智能技术生成

一、效果

如图所示,可以左右滑动,上下联动效果

 

二、代码

1.TopCollectionView

class TopCollectionView: UICollectionView ,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UIScrollViewDelegate{

    private var myContext = 0

    //这个是控制何时发送通知的

    var isManul:Bool = true

    var currentIndex:NSInteger = 0{

        didSet{

            if self.isManul==true {

                NotificationPost(CURRENTINDEX_TOP, currentIndex as AnyObject, userinfo: nil)

            }

        }

    }

    var date:NSArray = [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9]

 

    convenience init() {

        let flowLayOut = UICollectionViewFlowLayout.init()

        flowLayOut.scrollDirection = .horizontal

        flowLayOut.minimumLineSpacing = 0

        self.init(frame: CGRect.zero, collectionViewLayout: flowLayOut)

    }

 

   private override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {

        super.init(frame: frame, collectionViewLayout: layout)

        self.delegate = self

        self.dataSource = self

        self.backgroundColor = ColorClear

        self.layer.cornerRadius = AdWidth(10)

        self.clipsToBounds = true

        self.isPagingEnabled = true

        self.register(PictureCollectionCell.self, forCellWithReuseIdentifier: "PictureCollectionCell")

        NotificationRegister(CURRENTINDEX_BOTTOM, observer: self, selector: #selector(itemScroll(noti:)), object: nil)

 

    }

    

    required init?(coder aDecoder: NSCoder) {

        fatalError("init(coder:) has not been implemented")

    }

 

 

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

        return date.count

    }

    

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

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

        cell.setdateWithModel(currentIn

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值