我正在为iPhone制作一个绘图应用程序。在iPhone模拟器中它可以正常工作5秒钟,但随着我绘制的越来越多,它会越来越迟钝。当我在设备上测试时,它变得更加迟钝,我甚至无法绘制一棵简单的树。当我检查处理器在xcode中运行的百分比有多高时,通常会介于97-100%之间。有什么方法可以解决这个问题吗?
(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
currentPoint = [touch locationInView:self.view];
UIGraphicsBeginImageContext(CGSizeMake(320, 568));
[drawImage.image drawInRect:CGRectMake(0, 0, 320, 568)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0, 1, 0, 1);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGPathMoveToPoint(path, NULL, lastPoint.x, lastPoint.y);
CGPathAddLineToPoint(path, NULL, currentPoint.x, currentPoint.y);
CGContextAddPath(UIGraphicsGetCurrentContext(),path);
CGContextStrokePath(UIGraphicsGetCurrentContext());
[drawImage setFrame:CGRectMake(0, 0, 320, 568)];
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
[self.view addSubview:drawImage];
}
答案 0 :(得分:1)
在您的方法上运行仪器时,我得到以下结果:
告诉我的是什么:
答案 1 :(得分:1)