iOS: Drawing just portions of a UImage

后端 未结 1 965
误落风尘
误落风尘 2021-01-14 06:20

I am trying to draw just a custom portion of a UIImage (i.e.: I would like to reveal the portion of the UIImage user touches) and I am hav

相关标签:
1条回答
  • 2021-01-14 07:16

    One thing you could try is simply clipping instead of creating an extra layer. e.g.

    - (void)drawRect:(CGRect)rect
    {
        CGContextRef ctx = UIGraphicsGetCurrentContext();
    
        UIBezierPath *maskPath = [UIBezierPath bezierPath];
        [maskPath setLineWidth:10.0];
        [maskPath moveToPoint:CGPointMake(10.0, 10.0)];
        [maskPath addLineToPoint:CGPointMake(100.0, 100.0)];
    
        CGContextAddPath(ctx, maskPath.CGPath);
        CGContextClip(ctx)
        [img drawInRect:rect];
    }
    
    0 讨论(0)
提交回复
热议问题