[英]Images in UIPageViewController are repeating in UICollectionView on every time cell creates. Using library for displaying Images in scrollView
我有一个关于我使用在显示图像库的具体问题UIPageViewController
我在一个已经添加UICollectionView
, 这是图书馆 ,我使用,我的工作是通过对第一这个库做viewDidLoad
,但是当我滚动出现问题在CollectionView上下,它会不断重复UIpageViewController
的图像,以下是我遇到问题的代码。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: FeedsCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "FeedsCollectionViewCell", for: indexPath) as! FeedsCollectionViewCell
if postObject.contents.count > 0 {
for content in postObject.contents {
cell.feedImageHeightConstaint.constant = 200
cell.carouselViewHightContaint.constant = 200
let imageSlide = UIImageView()
let tap = UITapGestureRecognizer(target: self, action: #selector(showImage(_:)))
imageSlide.isUserInteractionEnabled = true
imageSlide.addGestureRecognizer(tap)
imageSlide.contentMode = UIView.ContentMode.scaleAspectFill
imageSlide.clipsToBounds = true
imageSlide.sd_setImage(with: URL(string: content.contentURL!), placeholderImage: nil) { [weak self](image, error, imageCacheType, url) in
guard let self = self else { return }
self.popUpFeedImage = image
}
cell.carouselView.appendContent(view: imageSlide) }
}
现在我想我知道这个问题是这个库只有追加函数但是这个函数没有删除它在新对象创建上的值,我试过修复它但我无法实现它,所以我发帖如果这里有任何帮助我能得到的将不胜感激。 有关理解我的问题的更多细节,请分享一个gif bellow。
我不太确定,但我认为你的问题在于
cell.carouselView.appendContent(view: imageSlide)
就像你说的那样,循环,图像不断重复,因为只有一个图像。 您的代码正在做什么:正在循环并设置值,当它完成时它将仅附加最后一个。 因为这就是它的结果。
如果我正确地读取你的代码,请尝试将append放在循环内部,它将是这样的:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: FeedsCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "FeedsCollectionViewCell", for: indexPath) as! FeedsCollectionViewCell
if postObject.contents.count > 0 {
for content in postObject.contents {
cell.feedImageHeightConstaint.constant = 200
cell.carouselViewHightContaint.constant = 200
let imageSlide = UIImageView()
let tap = UITapGestureRecognizer(target: self, action: #selector(showImage(_:)))
imageSlide.isUserInteractionEnabled = true
imageSlide.addGestureRecognizer(tap)
imageSlide.contentMode = UIView.ContentMode.scaleAspectFill
imageSlide.clipsToBounds = true
imageSlide.sd_setImage(with: URL(string: content.contentURL!), placeholderImage: nil) { [weak self](image, error, imageCacheType, url) in
guard let self = self else { return }
self.popUpFeedImage = image
cell.carouselView.appendContent(view: imageSlide)
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.