iPhone 在触摸位置清除 UIView alpha

标签 iphone ios transparent alpha quartz-core

我想在 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/

相关文章:

ios - 如何从我的 iOS 应用程序发送邮件 - SWIFT

ios - 如何快速使用 CLLocationManager 获取位置用户?

iphone - HTML 字符串设置为 UILabel

iOS:如何通过按 UIButton 更改 UIImageView

ios - 由于 iOS 10 中错误的随机数计数,HTTP 摘要身份验证失败

qt - 需要绘制包含使用 Qt 绘制圆的透明 qimage

html - 如何使 UIWebView 的 html 主体透明

ios - UINavigationController工具栏100%透明

ios - 有没有一种方法可以将应用程序部署到iOS设备而无需开发人员帐户或不通过Xcode?

iphone - 如何以用户位置为中心设置 map 矩形?