OGeek|极客世界-中国程序员成长平台

标题: iPhone在触摸位置清除UIView alpha [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:36
标题: iPhone在触摸位置清除UIView alpha

我想在 UIView 中呈现图像,因为我必须自定义 (void)drawRectCGRect)rect。我必须清除用户“摩擦”屏幕的 View 的 alpha,因此该 View 后面的 subview 将变得可见。
如果我使用纯色效果很好,但是当我尝试绘制图像并清除用户触摸屏幕的 View 时,不会绘制图像。 你能帮我,我应该如何绘制 UIImage,在背景中绘制并在特定的 rect 中变得透明,好吗?

这是我的代码,它适用于纯色(就像现在一样):

- (void)drawRectCGRect)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);
}



Best Answer-推荐答案


在 github 上已经有一个很好的控件用于此目的。 退房:

https://github.com/akopanev/iOS-Scratch-n-See

我已经用它作为“scratch game”应用程序的起点。 代理还会收到屏幕/图像有多少已被清除(即“划掉”)的信息。

祝你好运!

关于iPhone在触摸位置清除UIView alpha,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16016550/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4