【发布时间】:2014-08-14 12:10:48
【问题描述】:
我试图在点击时模糊 UICollectionViewCell。我尝试的是获取被点击的单元格的屏幕截图并模糊屏幕截图。使用模糊的屏幕截图作为背景并隐藏所有标签。
我注意到的行为是
点击单元格 1:单元格 1 消失
点击单元格 2:有点模糊,但我可以确定错误单元格的内容已被模糊
点击单元格 3:更加模糊
点击单元格 4:很多模糊
我认为的问题是:
错误的单元格内容变得模糊,
当另一个单元格模糊时,会重复使用模糊的屏幕截图,因此会增加模糊。
然后我编辑了代码以将背景设置为原始未模糊的屏幕截图
点击单元格 1:单元格 1 消失
点击单元格 2:出现单元格 1 的屏幕截图
点击单元格 3:出现单元格 2 的屏幕截图
等等
代码如下:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
//Code to get data from database and add to labels
if(![[modelArray objectAtIndex:indexPath.row] isEqualToString:@"1"]){
UIGraphicsBeginImageContextWithOptions(cell.overviewView.bounds.size, NO, cell.overviewView.window.screen.scale);
[cell.overviewView drawViewHierarchyInRect:cell.overviewView.frame afterScreenUpdates:NO];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
snapshotImage = [snapshotImage applyLightEffect];
cell.overviewView.backgroundColor = [UIColor colorWithPatternImage:snapshotImage];
cell.overviewView.alpha = 1;
cell.descLabel.alpha = 0;
cell.dayLabel.alpha = 0;
cell.weatherImage.alpha = 0;
cell.tempLabel.alpha = 0;
}
NSLog(@"Cell :%d condition : %@", indexPath.row, weather.desc );
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
WeekCell *cell = (WeekCell*)[collectionView cellForItemAtIndexPath:indexPath];
NSLog(@"%@", cell.descLabel.text);
if([[modelArray objectAtIndex:indexPath.row] isEqualToString:@"1"]){
[modelArray setObject:@"0" atIndexedSubscript:indexPath.row];
}else{
[modelArray setObject:@"1" atIndexedSubscript:indexPath.row];
}
NSLog(@"sequence : %@", modelArray);
[collectionView reloadItemsAtIndexPaths:@[indexPath]];
}
【问题讨论】:
-
你需要什么可以分享一张图片吗?
-
@Bhaskar 添加了一张图片
标签: objective-c ios7 uicollectionview uicollectionviewcell