我基本上希望为不同的目的创建类似于 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();
}
你要调用的方法是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
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)