我試圖找出如何可以展平或合併在石英2D動態地畫出的線條很多,「拼合」或「合併」石英2D繪製的線條
我上繪製隨機線隨着時間的推移我舞臺上,我每次加新線座標數組,並繪製陣列(我的drawRect我推在我的陣列定時器和setNeedDisplay新線acctually重繪以前所有的線條加上新)
現在的問題:一段時間後,它開始變得越來越慢,因爲陣列越來越很長,所以我雖然我應該合併座標轉換爲平面圖像或東西,並清除陣列到k eep它記憶健康,但我該如何做到這一點?
這是我的當前工作流:
呼叫計時器
[的NSTimer scheduledTimerWithTimeInterval:0.1目標:自選擇器:@selector(drawdrawdraw)USERINFO:無重複:YES];
刷新的drawRect在我的 「drawdrawdraw」 功能
- (無效)drawdrawdraw { [自setNeedsDisplay]; }
我的drawRect
-(void)drawRect:(CGRect)rect{ viewContext = UIGraphicsGetCurrentContext(); int count = [mijnArray_r_x count]; float r_x = (float)(random() % 768); [mijnArray_r_x insertObject:[NSNumber numberWithFloat:r_x] atIndex:count]; float r_y = (float)(random() % 1004); [mijnArray_r_y insertObject:[NSNumber numberWithFloat:r_y] atIndex:count]; float r_w = (float)(random() % 100); [mijnArray_r_w insertObject:[NSNumber numberWithFloat:r_w] atIndex:count]; float r_a = (float)(random() % 100); [mijnArray_r_a insertObject:[NSNumber numberWithFloat:r_a] atIndex:count]; CGContextSetLineWidth(viewContext, 2.0); CGContextSetStrokeColorWithColor(viewContext, [UIColor blackColor].CGColor); for (int k = 0; k <= count; k++) { float temp_x = [[mijnArray_r_x objectAtIndex: k] floatValue]; float temp_y = [[mijnArray_r_y objectAtIndex: k] floatValue]; float temp_w = [[mijnArray_r_w objectAtIndex: k] floatValue]; float temp_a = [[mijnArray_r_a objectAtIndex: k] floatValue]; CGPoint pointpointpoint = CGPointMake(temp_x, temp_y); CGPoint pointpointpointpoint = CGPointMake(temp_w, temp_a); CGContextMoveToPoint(viewContext, pointpointpoint.x, pointpointpoint.y); CGContextAddLineToPoint(viewContext, pointpointpoint.x - pointpointpointpoint.x, pointpointpoint.y + pointpointpointpoint.y); CGContextStrokePath(viewContext); } } }
作品!謝謝! :d – RecycleRobot 2011-01-16 12:38:17