我想在 UIView
中显示图像,因为我必须自定义 (void)drawRect:(CGRect)rect
。我必须清除用户“摩擦”屏幕时 View 的 alpha,以便此 View 后面的 subview 可见。
如果我使用纯色,效果很好,但是当我尝试绘制图像并清除用户触摸屏幕的 View 时,不会绘制图像。
你能帮我吗,我应该如何绘制 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);
}
最佳答案
github 上已经有一个用于该目的的良好控件。 查看:
https://github.com/akopanev/iOS-Scratch-n-See
我已经将其用作“刮刮游戏”应用程序的起点。 代表还会收到屏幕/图像的多少已经被清除(即“被刮掉”)的信息。
祝你好运!
关于iPhone 在触摸位置清除 UIView alpha,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16016550/