【问题标题】:Resizing an image when the cell in a UICollectionView has been expanded当 UICollectionView 中的单元格已展开时调整图像大小
【发布时间】:2015-03-30 09:18:41
【问题描述】:

我有一个照片库 (UICollectionView),它使用用户手机中的照片填充自己。仅允许单选,并且每当点击图像时,将向用户显示图像的放大版本。好吧,至少这就是我想要的。

问题在于放大部分。单元格本身的尺寸会增加,但图像仍然保持不变。

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
    {
        if indexPath == largePhotoIndexPath && indexPath.item != 0
        { 
            if let imageCell = collectionView.cellForItemAtIndexPath(indexPath)
            {
                var imgCell = imageCell as PhotoThumbnailCollectionViewCell
                var imgToEnlarge = imgCell.getThumbnailImage() as UIImage

                let size = CGSizeApplyAffineTransform(imgToEnlarge.size, CGAffineTransformMakeScale(0.5, 0.5))

                UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
                imgToEnlarge.drawInRect(CGRect(origin: CGPointZero, size: size))

                let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
                UIGraphicsEndImageContext()
            }

            return CGSize(width: 200, height: 200)
        }

        return self.cellDefSize! //normal size
    }

【问题讨论】:

    标签: ios swift uiimageview uiimage uicollectionview


    【解决方案1】:

    啊....我对此感到非常尴尬。 我忘了为 UIImageView 添加约束。添加后,问题就解决了。剩下的就是一些微调。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-24
      • 1970-01-01
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-28
      相关资源
      最近更新 更多