你或许可以用CGLayer来完成这项工作。
最重要的是,您应该能够使用您现有的代码将字符(或其他任何东西)绘制到CGLayer中。
下面是一些粗糙的代码:
// first, make a CGLayer...
CGLayerRef yourDrawingPad =
CGLayerCreateWithContext(UIGraphicsGetCurrentContext(),etc..
CGContextRef yourRef = CGLayerGetContext(yourDrawingPad);
// now, draw to yourRef .. draw your various typography (or anything)
// use your current drawing code.
// all done drawing, now make an image mask...
UIGraphicsBeginImageContext(CGLayerGetSize(yourDrawingPad));
CGContextRef temp = UIGraphicsGetCurrentContext();
CGContextDrawLayerAtPoint(temp, CGPointZero, yourDrawingPad);
CGImageRef anAlphaMask = CGBitmapContextCreateImage(temp);
UIGraphicsEndImageContext();
你现在有一个很好的面膜,你可以使用:
CGContextSaveGState(UIGraphicsGetCurrentContext()) ...
CGContextClipToMask(UIGraphicsGetCurrentContext(), self.frame, anAlphaMask);
所以只是掩盖它在一个梯度的图像,或任何作品。
(可以想象:也许你将不得不建立一个位图图像屏幕外,然后用其作为面罩)
脚注:不要忘了,很可能你将不得不倒挂画了!幸运的是,这很容易处理。它说:“现在,提请yourRef”绘图保存你的状态之前,并添加两行代码:
CGContextTranslateCTM(refForMask, 0, self.frame.size.height);
CGContextScaleCTM(refForMask, 1.0, -1.0);
希望它可以帮助
很奇怪。我发布了一条评论,但缺失。也许我没有正确添加它。所以这里再次。我会尝试两种方法。谢谢您的帮助。 – Ernesto 2011-02-20 15:02:16