간단한 테스트 응용 프로그램이 있습니다. 앱은 앱 위임자,보기 컨트롤러 및보기로 구성됩니다. 앱 대리자는보기 컨트롤러를 시작하고보기를 창에 추가합니다. 뷰 컨트롤러는 시작시 뷰를로드하고 다른 작업은 수행하지 않습니다. 보기는 다음과 같습니다.iOS - 예기치 않게 큰 사각형에 drawRect가 호출되는 경우가 있음
@implementation MyView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor blackColor];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
static NSDate* prevDate = nil;
NSDate* now = [NSDate date];
NSString* timeString = @"";
if (prevDate) {
NSTimeInterval dt = [now timeIntervalSinceDate:prevDate];
timeString = [NSString stringWithFormat:@"%d seconds", (int)dt];
}
prevDate = now;
NSLog (@"drawRect %@ %@", NSStringFromCGRect(rect), timeString);
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
CGRect rect = CGRectMake(point.x, point.y, 40, 40);
[self setNeedsDisplayInRect:rect];
}
@end
일부 내용은 다음과 같습니다. 왜 내가 이해하지 못하는 것은 왜 작은 직사각형 대신에 전체 화면에서 drawRect가 호출 되는가하는 것입니다.
모든 drawRect 호출은 터치 한 직후입니다. 이것은 예상대로입니다. 그런데 큰 직사각형을 지정하는 호출이있는 이유는 무엇입니까?
2011-12-13 12:46:15.004 DrawRectTest[1451:707] drawRect {{0, 0}, {1024, 748}}
2011-12-13 12:46:20.197 DrawRectTest[1451:707] drawRect {{0, 0}, {1024, 748}} 5 seconds
2011-12-13 12:46:23.235 DrawRectTest[1451:707] drawRect {{508, 475}, {40, 40}} 3 seconds
2011-12-13 12:46:27.671 DrawRectTest[1451:707] drawRect {{761, 484}, {40, 40}} 4 seconds
2011-12-13 12:46:36.394 DrawRectTest[1451:707] drawRect {{433, 254}, {40, 40}} 8 seconds
2011-12-13 12:46:51.190 DrawRectTest[1451:707] drawRect {{597, 270}, {40, 40}} 14 seconds
2011-12-13 12:47:04.979 DrawRectTest[1451:707] drawRect {{0, 0}, {1024, 748}} 13 seconds
2011-12-13 12:47:09.148 DrawRectTest[1451:707] drawRect {{0, 0}, {1024, 748}} 4 seconds
2011-12-13 12:47:14.314 DrawRectTest[1451:707] drawRect {{414, 480}, {40, 40}} 5 seconds
2011-12-13 12:47:31.343 DrawRectTest[1451:707] drawRect {{551, 503}, {40, 40}} 17 seconds
2011-12-13 12:47:33.639 DrawRectTest[1451:707] drawRect {{0, 0}, {1024, 748}} 2 seconds
2011-12-13 12:47:35.554 DrawRectTest[1451:707] drawRect {{521, 519}, {40, 40}} 1 seconds
2011-12-13 12:47:41.325 DrawRectTest[1451:707] drawRect {{366, 586}, {40, 40}} 5 seconds
2011-12-13 12:47:50.751 DrawRectTest[1451:707] drawRect {{535, 474}, {40, 40}} 9 seconds
2011-12-13 12:48:01.891 DrawRectTest[1451:707] drawRect {{0, 0}, {1024, 748}} 11 seconds
2011-12-13 12:49:24.600 DrawRectTest[1451:707] drawRect {{0, 0}, {1024, 748}} 82 seconds
2011-12-13 12:49:29.514 DrawRectTest[1451:707] drawRect {{0, 0}, {1024, 748}} 4 seconds
2011-12-13 12:49:30.774 DrawRectTest[1451:707] drawRect {{725, 372}, {40, 40}} 1 seconds
2011-12-13 12:50:04.435 DrawRectTest[1451:707] drawRect {{0, 0}, {1024, 748}} 33 seconds
2011-12-13 12:50:07.469 DrawRectTest[1451:707] drawRect {{0, 0}, {1024, 748}} 3 seconds
2011-12-13 12:50:09.417 DrawRectTest[1451:707] drawRect {{824, 471}, {40, 40}} 1 seconds
2011-12-13 12:51:04.550 DrawRectTest[1451:707] drawRect {{0, 0}, {1024, 748}} 55 seconds
2011-12-13 12:51:06.071 DrawRectTest[1451:707] drawRect {{0, 0}, {1024, 748}} 1 seconds
2011-12-13 12:51:07.809 DrawRectTest[1451:707] drawRect {{453, 557}, {40, 40}} 1 seconds
2011-12-13 12:51:11.776 DrawRectTest[1451:707] drawRect {{510, 370}, {40, 40}} 3 seconds
큰 프로젝트에서 성능을 향상시키려는 이유가 중요합니다. 속도 저하의 원인 중 하나는 비슷한 drawRect 호출입니다.
삼각형 전화 코드 란 무엇입니까? –