菜鸟教程小白 发表于 2022-12-12 10:36:21

iPhone在触摸位置清除UIView alpha


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

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



<pre><code>- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSaveGState(context);

    CGContextSetFillColorWithColor( context, .CGColor );
    CGContextFillRect( context, rect );

    CGContextSetFillColorWithColor( context, .CGColor );
    CGContextSetBlendMode(context, kCGBlendModeClear);
    CGContextFillRect(context, CGRectMake(lastTouch.x, lastTouch.y, 30, 30));

    CGContextRestoreGState(context);
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在 github 上已经有一个很好的控件用于此目的。
退房:</p>

<p> <a href="https://github.com/akopanev/iOS-Scratch-n-See" rel="noreferrer noopener nofollow">https://github.com/akopanev/iOS-Scratch-n-See</a> </p>

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

<p>祝你好运!</p></p>
                                   
                                                <p style="font-size: 20px;">关于iPhone在触摸位置清除UIView alpha,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/16016550/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/16016550/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iPhone在触摸位置清除UIView alpha