我創建了一個繪圖應用程序來繪製當您觸摸屏幕,它在模擬器中運行非常流暢,但是當我在iPad 2上測試它時,速度變慢並且需要很長時間才能繪製我正在使用這些代碼:繪圖應用程序性能
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
lastPoint = [touch locationInView:self.view];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
currentPoint = [touch locationInView:self.view];
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:self.view.frame];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 7.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0, 1, 0, 1);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
[drawImage setFrame:self.view.frame];
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
[self.view addSubview:drawImage];
}
我認爲這個問題是調用drawInRect:方法touchMoved:方法
嘗試使用Time Profiler工具分析此問題 - 它會告訴您哪些方法調用的處理時間最長。查看「Core Animation Essentials」WWDC視頻:https://developer.apple.com/videos/wwdc/2011/index.php – elimirks
這似乎是使用displayLink的好用的應用程序。無論發生多少次觸摸事件,每秒只能調用setNeedsDisplay這麼多次。 – Putz1103
是的,我知道在drawInRect:調用的錯誤,因爲當我刪除它工作順利,但繪圖並不完美在這種情況下 – user3330895