iphone - UICollectionViewCell 选择行为

标签 iphone ios objective-c uicollectionviewcell

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

我只需要实现苹果的默认选择行为,正如我们在相机胶卷中看到的那样。

enter image description here

现在我的选择是这样的

enter image description here

我已经实现了 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中,我将标签的框架设置为矩形,如图(绿色)所示。

方法 setSelected 如下所示:

- (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];
    }
}

那么,是否有可能拥有苹果的默认选择行为??

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

最佳答案

setSelected:如果选择的话,您的单元格的值为 YES然后添加一个白色UIView alpha 为0.5 (或将值调整为适合您的不透明度);如果NO ,删除该覆盖 View 。然后,当您添加复选标记图像时,请确保将其放置在覆盖 View 的顶部 [self.contentView bringSubviewToFront:checkmarkImageView] .

关于iphone - UICollectionViewCell 选择行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16209091/

相关文章:

ios - 绘制到缩放的 CGContext 中会产生全白图像

iphone - applicationDidBecomeActive 被调用两次

ios - 如何在 ios 中创建三角形对象

iphone - iPhone 设备的连接

iphone - 命令行编译 iPhone 应用程序

ios - UITextField 上的强密码覆盖

mysql - NSPredicate JOIN 两个表 OBJECTIVE C

objective-c - 未指定目标且未找到 makefile

ios - Objective C - IOS - 在类型对象上找不到属性 - 访问对象变量时

iPhone——是否可以在 Xcode 调试器中检查 UIView 的框架?