我有一个自定义的UIView,里面有一个二维数组。此数组包含我使用drawRect方法在自定义UIView上绘制的像素。
现在我想用100步(或者只用结果数组)改变这个像素(我的2维数组)。如何使此效果具有动画效果?这是没有问题的显示以前的状态,然后实际的状态,但我需要动画之间的状态。
谢谢你的帮助。
致以最好的问候,沃伊特克
更新,同一天,14:15
到目前为止,我是通过以下方式完成的:
- (void)calculate:(NSTimer *)timer {
int result = [myView calc];
if(result > 0)
{
[NSTimer scheduledTimerWithTimeInterval:0.00001f
target:self selector:@selector(calculate:)
userInfo:nil
repeats:NO];
}
[myView setNeedsDisplay];}但它并不是很好,因为刷新会使它变得非常慢。如果我每2-4次刷新一次计算,我的动画就不流畅。
我的绘图方法:
- (void)drawRect:(CGRect)rect{
int i = 0, j = 0;
CGContextRef myContext = UIGraphicsGetCurrentContext();
// ****************** drawing ********************
for(i = 0; i < 768; i++)
{
for(j = 0; j < 768; j++)
{
if(board[i][j] == 1)
{
CGContextSetRGBFillColor (myContext, 1, 0, 0, 1);
CGContextFillRect (myContext, CGRectMake (i, j, 1, 1));
}
else
{
CGContextSetRGBFillColor (myContext, 0, 0, 1, 1);
CGContextFillRect (myContext, CGRectMake (i, j, 1, 1));
}
}
}}
发布于 2010-12-29 21:46:18
使用fill rect一次绘制一个像素将需要一些时间。
我建议你设置一个内存区作为你想要绘制的图像,然后使用CGImageCreate创建一个可以在UIView中绘制的图像。
例如,使用see
http://www.iphonedevsdk.com/forum/iphone-sdk-development/23525-cgimagecreate-alpha.html
http://iphonedevelopment.blogspot.com/2009/04/creating-uiimages-from-tga-data.html
https://stackoverflow.com/questions/4553268
复制相似问题