我正在使用UICollectionView
生成图片库。我在UIImage
UICollectionView
内使用了Cell
来加载图片。我需要通过长按选择UICollectionView
Cell
(而不是单击)。
答案 0 :(得分: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
内。