Place a custom UIView over the view showing the image, size and position it to exactly overlap.
In the custom view's drawRect method
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGRect rBounds = self.bounds;
CGContextRef context = UIGraphicsGetCurrentContext();
// Fill background with 80% white
CGContextSetFillColorWithColor(context, [[[UIColor whiteColor] colorWithAlphaComponent:0.8] CGColor]);
CGContextFillRect(context, rBounds);
// Draw the window 'frame'
CGContextSetStrokeColorWithColor(context, [[UIColor orangeColor] CGColor]);
CGContextSetLineWidth(context, 10);
CGContextStrokeRect(context, self.maskRect);
// make the window transparent
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextFillRect(context, self.maskRect);
}
where maskRect is the rectangle to be shown transparent.
Do ensure that the background color of the custom view is set to 'clearColor'
You can write any additional logic required to change the maskRect and call 'setNeedsDisplay' on this view.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…