簡體   English   中英

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;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM