[英]How to animate inside UIView?
我有我的自定义UIView,其中有一个二维数组。 该数组包含我使用drawRect方法在自定义UIView上绘制的像素。
现在,我想以100步(或仅使用结果数组)更改此像素(我的2维数组)。 如何使该效果动起来? 先显示状态,然后显示实际状态是没有问题的,但是我需要在这些状态之间进行动画处理。
感谢您的任何帮助。
最好的问候,Wojtek
[更新,当天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));
}
}
}
}
一次使用填充矩形绘制一个像素将需要一些时间。
我建议您将存储区域设置为要绘制的图像,然后使用CGImageCreate创建可以在UIView中绘制的图像。
例如使用参见
http://www.iphonedevsdk.com/forum/iphone-sdk-development/23525-cgimagecreate-alpha.html
http://iphonedevelopment.blogspot.com/2009/04/creating-uiimages-from-tga-data.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.