CAShapeLayer 导致 UIImageView 中没有图像

CAShapeLayer resulting in no image in UIImageView

我正在尝试使 uiimageview 的顶角变圆,但是当绘制 CASharpeLayer 时,图像消失了,我不知道是什么导致了这个问题,我在 willDisplayCell 的代码下面。当单元格被重复使用时,图像会在绘制层中正确显示

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.imgProduct.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(3.0,3.0)];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = cell.imgProduct.bounds;
maskLayer.path = maskPath.CGPath;
cell.imgProduct.layer.mask = maskLayer;
cell.imgProduct.layer.masksToBounds=NO;

我自己解决了这个问题...:P 我已经在我的 UICollectionViewCell 子类的 drawRect 方法中绘制了遮罩

- (void)drawRect:(CGRect)rect {

    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.imgProduct.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(3.0, 3.0)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.imgProduct.bounds;
    maskLayer.path = maskPath.CGPath;
    _imgProduct.layer.mask = maskLayer;
    _imgProduct.layer.masksToBounds=YES;

}