我UICollectionView
用来生成图片库。我在UIImage
里面UICollectionView
Cell
用来加载图片。我需要UICollectionView
Cell
通过长按(而不是单击)进行选择。
问问题
2939 次
1 回答
2
只需拿起didSelectItemAtIndexPath
委托回调,抓取单元格,然后添加图像作为子视图。
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
YourCollectionViewCell *cell = (YourCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
UIImageView *yourImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, width, height)];//whichever frame you want it to appear at
yourImageView.image = [UIImage imageNamed:@"yourImageName"];//set the image
[cell.yourBaseImage addSubview:yourImageView];//or add it to whatever part of the cell you want
}
或者,只需在 Storyboard 中设置一个隐藏的 imageView。然后取消隐藏并将图像设置在里面didSelectItemAtIndexPath
。
于 2013-08-13T17:04:04.840 回答