Objective c 向UICollectionViewCell添加阴影会减慢滚动速度
通过向UICollectionViewCell添加以下代码,我能够成功地将阴影添加到UICollectionViewCell CellForItemIndexPath方法Objective c 向UICollectionViewCell添加阴影会减慢滚动速度,objective-c,uicollectionviewcell,Objective C,Uicollectionviewcell,通过向UICollectionViewCell添加以下代码,我能够成功地将阴影添加到UICollectionViewCell CellForItemIndexPath方法 cell.image.layer.masksToBounds = NO; cell.image.moviePlayerView.layer.shadowColor = [UIColor darkGrayColor].CGColor; cell.image.moviePlayerView.self.layer.shadowOff
cell.image.layer.masksToBounds = NO;
cell.image.moviePlayerView.layer.shadowColor = [UIColor darkGrayColor].CGColor;
cell.image.moviePlayerView.self.layer.shadowOffset = CGSizeMake(0, 5);
cell.image.moviePlayerView.self.layer.shadowRadius = 2;
cell.image.moviePlayerView.layer.shadowOpacity = 0.3;
但这会使滚动速度非常慢。我理解它在滚动时会给单元格添加阴影,但无法找到解决方案:/ 我找到了解决办法,希望这对其他人有所帮助。现在,我不再单独添加阴影,而是将现有图像与阴影图像合并,并使用结果图像
UIImage* image = [image imageWithFileShadow];
- (UIImage *)imageWithFileShadow {
static CGFloat pointScale = -1.0f;
if (pointScale < 0.0f) {
pointScale = [[UIScreen mainScreen] scale];
}
CGFloat imageWidth = (int)self.size.width;
CGFloat imageHeight = (int)self.size.height;
UIImage * shadowImage = [[UIImage imageNamed:@"FileShadowResizable"] resizableImageWithCapInsets:UIEdgeInsetsMake(20.0f, 24.0f, 29.0f, 24.0f)];
UIGraphicsBeginImageContextWithOptions(self.size, NO, pointScale);
[shadowImage drawInRect:CGRectMake(0.0f, 0.0f, imageWidth, imageHeight) blendMode:kCGBlendModeNormal alpha:1.0f];
[self drawInRect:CGRectMake(14.0f, 8.0f, self.size.width - 28.0f, self.size.height - 29.0f)];
UIImage * mergedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return mergedImage;
}