我想在 a 中呈现图像UIView
,因为我必须自定义(void)drawRect:(CGRect)rect
. 我必须清除用户“摩擦”屏幕的视图的 alpha,因此该视图后面的子视图将变得可见。
如果我使用纯色效果很好,但是当我尝试绘制图像并清除用户触摸屏幕的视图时,不会绘制图像。你能帮我吗,我应该如何UIImage
绘制 , 在背景中绘制并在特定rect中变得透明,好吗?
这是我的代码,它适用于纯色(就像现在一样):
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetFillColorWithColor( context, [UIColor greenColor].CGColor );
CGContextFillRect( context, rect );
CGContextSetFillColorWithColor( context, [UIColor clearColor].CGColor );
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextFillRect(context, CGRectMake(lastTouch.x, lastTouch.y, 30, 30));
CGContextRestoreGState(context);
}