gpt4 book ai didi

iphone - UICollectionViewCell 选择行为

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:10:26 26 4
gpt4 key购买 nike

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

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

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 。然后,当您添加复选标记图像时,请确保使用 [self.contentView bringSubviewToFront:checkmarkImageView] 将其分层放置在叠加 View 之上。

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com