有没有办法在其上点击的CollectionViewCell上添加半透明叠加层? (当用户点击单元格时,我希望"变暗"整个单元格。)
我找到了改变背景颜色的方法,但我不知道是否有添加叠加层的方法。
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
[UIView animateWithDuration:0.1 delay:0 options:(UIViewAnimationOptionAllowUserInteraction) animations:^{ [cell setBackgroundColor:[UIColor colorWithRed:232/255.0f green:232/255.0f blue:232/255.0f alpha:1]]; } completion:nil];
}
修改
一旦点击了Cell,我就为它添加了一个半透明背景的UIView:
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 172, 210)];
overlay.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
[cell addSubview:overlay];
}
答案 0 :(得分:0)
我发现,最简单的解决方案是从一开始就添加一个没有图像但带有突出显示图像的UIImageView:
im
结果是,当 - 并且仅在 - 突出显示(选择)单元格时,图像newmtl M_WhiteEditQuarter_M_WhiteEditQuarter
map_Kd assets/M_WhiteEditQuarter_M_WhiteEditQuarter_D.dds
map_Ks assets/M_WhiteEditQuarter_M_WhiteEditQuarter_S.dds
bump assets/M_WhiteEditQuarter_M_WhiteEditQuarter_N.dds
在单元格中神奇地变得可见。