Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.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 UICollectionViewCell选择行为_Iphone_Ios_Objective C_Uicollectionviewcell - Fatal编程技术网

Iphone UICollectionViewCell选择行为

Iphone UICollectionViewCell选择行为,iphone,ios,objective-c,uicollectionviewcell,Iphone,Ios,Objective C,Uicollectionviewcell,我的应用程序中有一个照片库。我可以选择多张照片并删除它们。一切都进行得很顺利 我只需要实现apple的默认选择行为,正如我们在camera roll中看到的那样 现在我的选择是这样的 我已经实现了如下的didSelectItemAtIndexPath方法- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { NSLog

我的应用程序中有一个照片库。我可以选择多张照片并删除它们。一切都进行得很顺利

我只需要实现apple的默认选择行为,正如我们在camera roll中看到的那样

现在我的选择是这样的

我已经实现了如下的didSelectItemAtIndexPath方法-

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Delegate cell %@ : SELECTED", [self formatIndexPath:indexPath]);
    MyCustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.label.backgroundColor=[UIColor greenColor];
}

 - (NSString *)formatIndexPath:(NSIndexPath *)indexPath 
{
    return [NSString stringWithFormat:@"%ld", (long)indexPath.row+1];
}
在MyCustomCell.m中,我将标签的框架设置为矩形,如图(绿色)所示

方法如下所示:

- (void)setSelected:(BOOL)selected
{
    UIView *blurView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 70)];
    blurView.backgroundColor=[UIColor whiteColor];
    blurView.alpha=0.5;
    blurView.opaque=YES;
    if (selected) {
        self.label.backgroundColor = [UIColor greenColor];
        [self.imageThumb addSubview:blurView];
    }
}
那么,有可能有苹果的默认选择行为吗


任何帮助都将不胜感激。提前感谢。

只需在UIImageView上添加一个具有所需灰色的UIView即可。 将alpha设置为f.e.0.5,隐藏=是

_blurView.hidden = YES;
_blurView.alpha = 0.5;
如果选中,则将hidden设置为NO

_blurView.hidden = NO;
您可以使用InterfaceBuilder添加UIView


为了让它看起来更好,你可能会使用一个带有漂亮纹理图像的UIImageView。

在你的单元格的
设置中:
,如果选择的是
,然后添加一个白色
UIView
,alpha值为
0.5
(或者将该值调整为你认为合适的不透明度);如果
,请删除该覆盖视图。然后,当您添加复选标记图像时,请确保使用
[self.contentView bringsubview tofront:checkmarkImageView]

@Jacky Boy我已编辑了我的问题。我无法在选择中获得灰显效果。请显示处理选择的代码。我添加了几行代码。@Micro我尝试过,但对我无效。设置cell.alpha会使我的手机看起来很暗,但不会像提供的图像那样变灰/模糊。我更改了答案,这可能会对你有所帮助?!谢谢你的回答。这对我有用。我有一个问题-当我将“不透明”设置为true时,当我没有使用“不透明”属性时,它不会对以前的结果进行任何更改。那么,你能帮我设置不透明度吗?你将哪个视图设置为不透明度?你能用你最新的代码更新这个问题吗?这个答案解释得很好:哇,完美的解释。谢谢。谢谢你的帮助。:)还有一个问题-我尝试删除覆盖视图,正如你前面所说,当未选中时。但这对我不起作用。我尝试在setSelected方法的else部分添加代码以删除blurView。