[英]Why does my Coregraphics drawingcode cause lag?
I'm working on an drawing app for iPhone. 我正在为iPhone设计绘图应用程序。 It works fine for like 5 seconds in the iPhone simulator but as more I draw it gets more laggy.
在iPhone模拟器中,它可以正常工作约5秒钟,但随着我画的越多,它就会变得越滞后。 When I test it on the device it gets even more laggy and I can't even draw a simple tree.
当我在设备上对其进行测试时,它变得更加笨拙,甚至无法绘制简单的树。 When I check how high percent the processor is running at in xcode it usually go between 97-100%.
当我检查处理器在xcode中运行的百分比时,通常在97-100%之间。 Is there any way to fix this?
有没有什么办法解决这一问题?
(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];
}
When running instruments on your method, I got the following results: 使用您的方法运行仪器时,得到以下结果:
What that tells me: 那告诉我的是:
There's a great talk about graphics performance including a demo and code walkthrough of a drawing app here: 这里有很多关于图形性能的讨论,包括演示和绘图应用程序的代码演练:
https://developer.apple.com/videos/wwdc/2012/ https://developer.apple.com/videos/wwdc/2012/
The iOS App Performance: Graphics and Animations video iOS应用性能:图形和动画视频
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.