[英]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.