ios - 我将如何显示多个视频、图像?当我上传多张图片和视频时
解决方案
您可以使用 SizeForItemAt 函数为每个单元格设置自定义大小,并在最后一个单元格内添加一个按钮以打开最后两个图像,或使用 didSelectItemAt 打开最后一个单元格。
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
{
var collectionViewSize = collectionView.frame.size
if indexPath.row == 0 {
collectionViewSize.width = collectionViewSize.width/2.0 //Display 2 items in a row.
collectionViewSize.height = collectionViewSize.height/2.0
}
if indexPath.row == 1 {
collectionViewSize.width = collectionViewSize.width/3.0 //Display 3 items in row
collectionViewSize.height = collectionViewSize.height/2.0
}
return collectionViewSize
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return yourImageArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "YourCustomCell", for: indexPath) as! YourCustomCell
cell.imageView.image = yourImageArray[indexPath.item] as UIImage
return cell
}
*记得在你的 ViewController 中设置 UICollectionViewDelegateFlowLayout
推荐阅读
- postgresql - 将 postgres JSON 转换为行
- excel - 如何通过范围内的 ID 和日期过滤找到最大值和最小值
- core-data - Previewing ContentView with CoreData
- multithreading - 优化 OpenCL 缓冲区写入?
- pandas - 递归地列出树/有向图中节点的邻居,对于图中的所有节点,一次一个“级别”?
- here-api - Fleet Telematics Waypoints Sequence response time
- java - 在 Scala 中对 Java 列表进行平面映射
- android - 尝试 UnitTest 时,出现 Jacoco 错误。即使它没有使用
- google-cloud-platform - Terraform:自动进行身份验证以将 GCP 存储桶挂载到 VM
- c++ - 在初始化列表中强制转换 shared_ptr