【发布时间】:2010-12-29 10:24:00
【问题描述】:
我有我的自定义 UIView,里面有一个二维数组。该数组包含我使用 drawRect 方法在自定义 UIView 上绘制的像素。
现在我想用 100 步(或只用结果数组)更改这个像素(我的 2-dim 数组)。如何使这种效果动画化?显示以前的状态然后显示实际状态是没有问题的,但是我需要在这些状态之间进行动画。
感谢您的帮助。
最好的问候, 沃伊泰克
[更新,同一天,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));
}
}
}
}
【问题讨论】:
标签: objective-c cocoa-touch ios uiview