2012-03-05 2 views
1

나는 아래 코드와 함께 iPad에서 테스트를 마쳤습니다.MKOverlayView 성능 문제. 아무것도하지 않고. 그러나 천천히

아래 코드와 같이 MyOverlay를 추가하면 drawMapRect에서 아무 작업도하지 않아도 기본지도 타일의 MKMapView로드가 느려집니다.

그리고 MKMapView에서 MyOverlay를 제거하면 기본지도 타일의로드가 다시 빠릅니다.

drawMapRect가 호출 될 때 백그라운드에서 수행되는 작업이 궁금합니다.

아래 코드는 성능에 어떤 문제가 있습니까?

[코드]

@implementation MyOverlay 

-(id) init 
{ 
    self = [super init]; 

    boundingMapRect = MKMapRectWorld; 
    boundingMapRect.origin.x += 1048600.0; 
    boundingMapRect.origin.y += 1048600.0; 

    coordinate = CLLocationCoordinate2DMake(0, 0); 

    return self; 
} 

... 
@end 


@implementation MyOverlayView 

- (id) initWithOverlay:(id<MKOverlay>)overlay 
{ 
    self = [super initWithOverlay:overlay]; 

    ... 
    return self; 
} 

- (BOOL) canDrawMapRect:(MKMapRect) sm zoomScale:(MKZoomScale)zoomScale 
{ 
    return true; 
} 

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext: CGContextRef)context 
{ 
    return; // do nothing, but map loading become slower 'much'. 
} 
@end 

답변

0

가 MKOverlayView 드로잉 방법 drawMapRect:zoomScale:inContext:의 이름으로 UIView drawRect의 방법을 생각 나게한다. 그리고 MKOverlayView는 UIView의 하위 클래스입니다. 있는 UIView의 서브 클래스가이 경고 제공 : 이것은 문제가 여전히 경우이 SO 질문을 살펴해야한다,

/* 
// Only override drawRect: if you perform custom drawing. 
// An empty implementation adversely affects performance during animation. 
- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
} 
*/ 

을 약 drawRect의 성능 : to drawRect or not to drawRect (when should one use drawRect/Core Graphics vs subviews/images and why?)