我想知道是否可以使用CoreGraphics绘制的路径的填充颜色动画? 我正在绘制: Simple drawing with Quartz - Core Graphics如何在drawRect中为使用CGContextDrawPath等绘制的路径填充颜色?
我想将其填充颜色从白色改为灰色。 这可能吗?
我知道view.layer.content属性的存在,但在这里有用吗?虽然,我不确定在这种情况下如何使用它。
在此先感谢。
更新
我想这种方式(其越野车,所以我可以告诉大家,如果它去上班) 基本上我创建一个CGImageRef,并把它传递给self.layer.contents这是动画 使用UIView动画,但....我得到奇怪的结果,除了不是动画。
int bitsPerComponent = 8;
int channels = 4;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
void *data = malloc(self.bounds.size.width*self.bounds.size.height*channels);
CGContextRef context = CGBitmapContextCreate(data, //pointer to data
self.bounds.size.width, //width
self.bounds.size.height, //height
bitsPerComponent, //bitsPerComponent
self.bounds.size.width*channels,//bytesPerRow
colorSpace, //colorSpace
kCGImageAlphaPremultipliedFirst); //bitmapInfo
//method that uses below link's code
[self _drawBackgroundInContext:context color:UIColorFromMandalaBoxType(type)];
CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, //info, NULL
data, //pointer to data
self.bounds.size.width*self.bounds.size.height*channels, //number of bytes
NULL); //release callback
CGImageRef image = CGImageCreate(self.bounds.size.width, //width
self.bounds.size.height, //height
bitsPerComponent, //bitsPerComponent
bitsPerComponent*channels, //bitsPerPixel
self.bounds.size.width*channels, //bytesPerRow
colorSpace, //colorSpace
kCGImageAlphaPremultipliedFirst, //bitmapInfo
dataProvider, NULL, false, kCGRenderingIntentDefault);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5f];
self.layer.contents = (id)image;
[UIView commitAnimations];
CGImageRelease(image);
CGDataProviderRelease(dataProvider);
CGContextRelease(context);
free(data);
CGColorSpaceRelease(colorSpace);
是逻辑好吗?,这里的错误在哪里? (
那该怎么做动画? – Eiko 2010-11-08 23:47:53
哦,对不起,要么我误读了你的问题,要么以后编辑过。我没有意识到你正在尝试制作动画。我会编辑我的答案以包含一个动画版本。 – 2010-11-09 02:31:51