首页 > 解决方案 > 如何用动画改变 uicollectionviewcell 的位置?

问题描述

我正在设计一个这样的朋友列表屏幕animation

在此处输入图像描述

我开始了,collectionview但我不明白如何改变cells.

uicollectionviewcell为图像,名称和第二个用于列表等所有详细信息。

我还设法将集合更改为列表,但animation我不知道该怎么做。

这是我的代码:

//MARK: - Collection view setUp -
extension CollViewAnimate {

    fileprivate func setUpCollView() {

        self.delegate = self
        self.dataSource = self

        self.register(UINib(nibName: "NameCollCell", bundle: nil), forCellWithReuseIdentifier: "NameCollCell")
        self.register(UINib(nibName: "DetailCollCell", bundle: nil), forCellWithReuseIdentifier: "DetailCollCell")
    }

    func reloadTblData() {

        self.isList = !self.isList
        self.reloadData()
    }
}

//MARK: - Collection view Deleagtes & DataSources -
extension CollViewAnimate: UICollectionViewDelegate, UICollectionViewDataSource {

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.arrFriendList.count
    }

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


        if self.isList {

            if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "DetailCollCell", for: indexPath) as? DetailCollCell {

                cell.setUserDetails(self.arrFriendList[indexPath.row])

                return cell
            }

        } else {

            if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "NameCollCell", for: indexPath) as? NameCollCell {

                cell.setUserDetails(self.arrFriendList[indexPath.row])

                return cell
            }
        }

        return UICollectionViewCell(frame: .zero)
    }
}

//MARK: - Collection view FlowLayout Deleagtes -
extension CollViewAnimate: UICollectionViewDelegateFlowLayout {

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

        if self.isList {
            return CGSize(width: (collectionView.frame.width), height: (collectionView.frame.width / 5))
        }

        return CGSize(width: (collectionView.frame.width / 3), height: (collectionView.frame.width / 2.5))
    }
}

这里我使用了单独的集合视图文件,我的所有代码collectionview都在这里返回,.xib文件为collectionviewcell.

请指导我完成这项任务,也给你建议一个合适的controller.

谢谢

标签: iosswiftuicollectionviewuicollectionviewcelluianimation

解决方案


推荐阅读