我试图找出如何可以展平或合并在石英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