ios - Swift:ScrollView 根据单元格图像大小滚动
问题描述
我有一个viewController
which hasCollectionView
并且 collectionView 单元格包含ImageView
并且响应来自api
. 而且viewController orientation
是Landscape
。所以问题是当我滚动图像时它没有正确滚动。这是附加图像。
那么如何根据Scrolling action
我的图像大小进行设置。所以它在视图中只显示图像。这是我的代码。
extension GalleryViewController : UICollectionViewDataSource , UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCell", for: indexPath) as! ImageCell
let image = arrImgs[indexPath.row]
cell.lblIndex.text = "< \(indexPath.row+1) / \(arrImgs.count) > Images"
if let imgUrl = URL.init(string: image.Message) {
cell.imgV.sd_setImage(with: imgUrl) { (img, error, casheType, url) in
DispatchQueue.main.async {
cell.imgV.image = img
}
}
}
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return arrImgs.count
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize.init(width: width, height: height)
}
}
class ImageCell: UICollectionViewCell {
@IBOutlet var lblIndex: UILabel!
@IBOutlet var imgV: UIImageView!
}
这是我的StoryBord
安排。
谢谢。
解决方案
推荐阅读
- shell - 无法使用 Nifi curl 命令启动处理器
- angularjs - 在另一个工厂中使用工厂是未定义的 - AngularJS
- html - 悬停子菜单不会保持打开状态
- c++ - “float = float - float”中是否存在隐式类型提升?
- php - How to implement order by in with string which contain alphabet and number
- reactjs - 在 Django 中使用 cookie 进行会话身份验证不起作用
- android - Android自定义视图绘制
- javascript - 匹配时删除登录页面中的错误消息
- javascript - 从命令行使用无头 chrome 执行单个 Javascript 文件
- r - 基于列表 dplyr 添加列