我有一个照片库(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
}
答案 0 :(得分:0)