ios - 如何用动画改变 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
.
谢谢
解决方案
推荐阅读
- python - 如何使用 selenium 在具有 AJAX onchange 属性的下拉菜单中选择一个选项
- couchbase - 使用数组函数从数组中删除元素不起作用
- javascript - 带有字符串值的 Google 脚本 .setFormula 错误
- python - NLTK Punkt Tokenizer:如何自定义句尾字符?
- laravel - 渴望加载媒体网址 - laravel-medialibrary
- python - 同一组内的时间戳差异
- django - 使用 python 3.8 在 Windows 10 上安装 django 频道和扭曲的问题
- angular - 什么是等价的承诺
在可观察的? - java - 当我尝试共享文件时,它的节目格式不支持味精
- javascript - 影响未链接到它的 div 的脚本