1

通过将以下代码添加到 cellForItemAtIndexPath 方法,我能够成功地将阴影添加到 UICollectionViewCell

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;

但它使滚动真的很慢。我理解它在滚动时向单元格添加阴影但无法找出解决方案。:/

4

1 回答 1

0

我想出了解决方案,希望这对其他人有帮助。现在我将现有图像与阴影图像合并并使用结果图像,而不是单独添加阴影。

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;
}
于 2013-03-14T19:04:42.857 回答