2

我基本上是在寻找类似于非常简单的 iSteam/iFog alebit 版本的东西,用于不同的目的。实际上会有两个图像,一个是主题,另一个是凝结或类似的图像。然后,用户可以用手指在屏幕上擦拭,它会从顶层“剪掉”手指,露出下层。到目前为止,我已经能够使用 CoreGraphics 和笔画在屏幕上绘制一条基本线,但我找不到将其用作蒸汽层的 alpha 蒙版的方法。

如果有人能给我关于使用什么甚至更好的示例代码的建议,我将非常感激,因为现在我正在拔头发。这是我到目前为止所拥有的:


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

mouseSwiped = YES;
UITouch *touch = [touches anyObject];   
CGPoint currentPoint = [touch locationInView:self.view];
UIGraphicsBeginImageContext(self.view.frame.size);
CGRect rect = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[drawImage.image drawInRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, 36.0);
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextBeginPath(context);

CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);
CGContextStrokePath(context);
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();

}

4

1 回答 1

3

您要调用的方法是CGContextClipToMask. 只需绘制您的“蒸汽”图像,然后在另一个 CGImage 上进行描边。然后,将蒸汽夹在中风处。像这样的东西:

- (void)somewhereElse{
    UIImage *steam = [[UIImage imageNamed:@"steamImage.png"] retain];
    steamRef = steam.CGImage;
    //...
}

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextDrawImage(context, self.bounds, steamRef);         //draw the main image
    CGContextClipToMask(context, self.bounds, maskRef);         //respect alpha mask
    //where maskRef is a GCImage of your stroked path
}
于 2010-02-06T00:22:49.973 回答