iPad에서 "그리기 응용 프로그램"을 그리면 엄청난 양의 메모리가 사용되어 결국에는 충돌이 일어납니다 (또는 최소한 선을 그릴 때는 매우 지루함). "Drawing apps"에 대한 예제를 많이 보았습니다. 나는 그 중 2 개가 효과가 있다는 것을 알았지 만, 그 둘을 그리려 할 때 모두 뒤떨어져있었습니다.Core Graphics 드로잉 코드가 느리게 실행되는 이유는 무엇입니까?
), 나는 아이폰/아이 패드 시뮬레이터를 사용하는 경우입니다 원활립니다,하지만 내 아이 패드 2 세대에 많이 :(이 사람을 도움이 될 것입니다 경우 내 응용 프로그램의 진짜 목적은,는 "서명 응용 프로그램"입니다를 지연
앱 그리기에 대한 경험이 있거나 (코드가 잘못된 부분을 볼 수있는 경우) 대답을 남겨주세요. 그것은 인정 될 것이다!
내 코드는 (또한 스크린 샷) 아래에 나열되어:
ViewController.m :
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
drawImage = [[UIImageView alloc] initWithImage:nil];
drawImage.frame = self.view.frame;
[self.view addSubview:drawImage];
self.view.backgroundColor = [UIColor lightGrayColor];
mouseMoved = 0;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = NO;
UITouch *touch = [touches anyObject];
lastPoint = [touch locationInView:self.view];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 3.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 255.0, 255.0, 255.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
mouseMoved++;
if (mouseMoved == 10) {
mouseMoved = 0;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if(!mouseSwiped) {
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 3.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 255.0, 255.0, 255.0, 1.0);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
ViewController.h : 성능의 대부분
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
CGPoint lastPoint;
UIImageView *drawImage;
BOOL mouseSwiped;
int mouseMoved;
}
@end
Instruments 또는 다른 도구를 사용하여 코드를 프로파일 링하고 성능을 테스트 해 보셨습니까? 우리는 단순히 당신에게 대답을 줄 것을 기대할 수 없습니다. – SevenBits