代码之家  ›  专栏  ›  技术社区  ›  Waliyan

未在UICollectionView单元格Swift 4内的ImageView上加载完整图像

  •  0
  • Waliyan  · 技术社区  · 8 年前

    我使用自动调整大小,使所有设备的图像大小合适。在UICollectionView单元格中放置UIView。在UIView上,我放置了一个视图宽度相等的ImageView和另一个视图,其中包含一些内容。现在我对所有的设备都使用了Autoresize,但是iphone6splus和iPad的图片大小不同,我对所有的内容模式都做了修改,但还是一样的。我的CollectionViewLayout代码如下。

         func collectionView(_ collectionView: UICollectionView,
                        layout collectionViewLayout: UICollectionViewLayout,
                        sizeForItemAt indexPath: IndexPath) -> CGSize {
    
        if collectionView == collection || collectionView == collection_favourite{
    
    
                return CGSize(width: display_width / 2, height: 290)
    
            }
    
        }
    

    当我使用调试视图层次结构时,似乎我的ImageView的大小正好是我想要的(显示在下面带有蓝色阴影的图像中是我的ImageView),但是上面显示的图像发生了偏移,或者没有正确显示。我不知道如何处理它,我做了这么多的更改,但是没有解决。请帮助获取这个。提前谢谢

    enter image description here

    enter image description here

    在此处输入图像描述

    enter image description here

    enter image description here

    enter image description here

    1 回复  |  直到 8 年前
        1
  •  0
  •   SThakur    8 年前

    UIImageview的内容模式是什么?您是否正在调用cellForItemAtIndexPath中的layoutIfNeeded?