2014-09-09 2 views
2

앱의 경우 MKMapView에 MKCircle 주석을 추가해야합니다. 그러나 원을 이동/크기 조정해야합니다. 이 질문에 답을 얻었습니다. Moving MKCircle in MKMapView 주석을 제거/추가하면 해당 동작을 얻는 것이 좋습니다.MKOverlayRenderer에서 drawRect가 느린 이유

그러나이 게시물의 사용자와 같이 그림이 매우 느립니다. Smooth resizing of MKCircle. 이제이 질문에 대한 답변이 있으므로 YHAnimatedCircleView을 사용하는 것으로 보입니다. 천천히 말하자면 UISlider를 사용하여 원의 반경을 변경하면 다시 그리는 것이 엉성한 것이며 타일을 그리는 데 타일이 사용됨을 알 수 있습니다.

서브 테스트 MKOverlayRenderer의 drawMapRect을 무시하고 작은 테스트 코드를 만들었습니다. 나는 오래된 주석이 제거 된 UISlider를 이동하면

-(void) drawMapRect:(MKMapRect)mapRect 
      zoomScale:(MKZoomScale)zoomScale 
      inContext:(CGContextRef)context 
{ 
    MKCircle* circleOverlay = (MKCircle*)self.overlay; 

    CLLocationCoordinate2D point = circleOverlay.coordinate;   

    CGPoint locationPoint = 
     [self pointForMapPoint:MKMapPointForCoordinate(point)]; 

    CGFloat radius = 
     MKMapPointsPerMeterAtLatitude(circleOverlay.coordinate.latitude) * 
     circleOverlay.radius; 

    CGRect circleRect = CGRectMake(locationPoint.x - radius, 
            locationPoint.y - radius, 
            radius * 2.0, radius * 2.0); 

    CGContextSaveGState(context);  

    CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor); 
    CGContextFillEllipseInRect(context, circleRect); 

    CGContextRestoreGState(context); 
} 

다른 반경 새로운 MKCircle 배치하고 drawMapRect 메서드가 호출됩니다 다음과 같이 코드입니다.

그러나이 작은 예제조차도 원의 크기를 조정할 때 엉성한 그림을 보여줍니다.

질문 :

  1. 위의 예는 완전히 올바른 또는 내가 그림에 뭔가를하고있는 중이 야인가?
  2. 예제가 정확하다면 너무 작거나 천천히 크기를 조정할 때 원을 다시 그리는 이유는 무엇입니까?
+0

안녕하세요 @SebastianDressler, 문제를 해결할 수 있었습니까? 나는 그걸로 어려움을 겪고 있는데, 모든 것을 시도했지만 아무 것도 효과가없는 것처럼 보입니다. – bevoy

+0

아니, 나는 한 번도하지 않았다. AFAIK 참조로 사용할 수있는 YHAnimatedCircleView 만 있지만, 어떤 이유로 든 좋아하지 않습니다.내 솔루션은 내가 다르게 사용하는 핀 색상을 지정하는 것이 었습니다. –

답변

0

MKMapView에서 오버레이를 그리는 것과 비슷한 문제가 있었지만 문제는지도와 관련하여 그려진 원을 움직이는 것이 었습니다. 이것은 서클의 움직임과 비교하여지도의 움직임이 지연되는 문제를 일으켰습니다. 서클이지도 위에 고정되는 것과 달리지도의 위쪽으로 미끄러지는 것처럼 보입니다.

내 솔루션은 MKMapView의 드로잉과 내가 추가 한 뷰를 동기화하기 위해 CADisplayLink을 사용했습니다. UISlider를 사용하여 원의 반지름을 변경하는 방법을 원래대로 구현할 수 있다고 생각하지만 구현하지 않아도 철저히 테스트 할 수는 없습니다.

코드 예제는 다음과 같이이다 :이 문제에 당신을 도움이되기를 바랍니다

- (void)viewDidLoad { 
    self.mapUpdateLink = [CADisplayLink displayLinkWithTarget:self 
               selector:@selector(updateMapView)]; 
    [self.mapUpdateLink addToRunLoop:[NSRunLoop mainRunLoop] 
          forMode:NSRunLoopCommonModes]; 
} 

- (void)updateMapView { 
    CGPoint centerPoint = [self.mapView convertCoordinate:self.circleView.centerCoordinate 
              toPointToView:self.view]; 
    if (!isnan(centerPoint.x) && !isnan(centerPoint.y)) { 
     self.circleView.center = centerPoint; 
    } 
} 

.

0

내가 아는 한 MKMapView의 drawRect는 매우 느립니다.

(CCHMapClusterControlleralso found out that를 만든 호기심 사람들은) 내가 할 것 대신 일을 그리기 RECT의있는 UIImage 생성 할 수 있습니다 : 당신이 많은 링크처럼 (AN AnnotationView에 layoutSubViews에서 해당 이미지를 생성 할 수 있습니다

UIImage *circle; 

CGRect circleRect = CGRectMake(locationPoint.x - radius, 
           locationPoint.y - radius, 
           radius * 2.0, radius * 2.0); 

UIGraphicsBeginImageContextWithOptions(CGSizeMake(radius * 2.0, radius * 2.0), NO, 0.0f); 

CGContextRef ctx = UIGraphicsGetCurrentContext(); 
CGContextSaveGState(ctx); 



CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor); 
CGContextFillEllipseInRect(context, circleRect); 

CGContextRestoreGState(ctx); 
    circle = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

을 보여줍니다 :)). AnnotationView는 반경을 가질 수 있으며 UISlider는 반경을 변경합니다. setRadius 속성에서 setNeedsLayout이라고 부릅니다.

관련 문제