Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone IOS:在UICollectionView单元格上添加覆盖图像_Iphone_Ios_Uicollectionview - Fatal编程技术网

Iphone IOS:在UICollectionView单元格上添加覆盖图像

Iphone IOS:在UICollectionView单元格上添加覆盖图像,iphone,ios,uicollectionview,Iphone,Ios,Uicollectionview,我正在使用UICollectionView生成图像库。我在UICollectionView单元格中使用UIImage加载图像。我需要长按选择UICollectionView单元格。只需拿起didSelectItemAtIndexPath代理回调,抓取单元格,并将图像添加为子视图 -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

我正在使用
UICollectionView
生成图像库。我在
UICollectionView
单元格中使用
UIImage
加载图像。我需要长按选择
UICollectionView
单元格

只需拿起
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
}

或者,也可以在故事板内部设置一个隐藏的imageView。然后将其取消隐藏并将图像设置在
didSelectItemAtIndexPath

中,效果非常好。谢谢,没问题!祝你一切顺利!,如何使用DIDDeselectItemIndexPath方法删除特定单元格的覆盖图像?谢谢你难道不认为这会把滚动和单元格重用搞砸吗?当手机离开屏幕后又重新打开时会发生什么?它失去了是否被选中的状态。正确的方法是改变模型对象的状态,让单元格从中提取。最后一行的“yourBaseImage”是什么?