Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

iphone - MKOverlay not resizing smoothly

I have added a MKCircle as MKOverlay to my MKMapView. Also I added an UISlider to decide the radius of the circle. Unfortunately when using this it seems a bit "laggy", not smootly like I want it to be.

Example: http://dl.dropbox.com/u/3077127/mkoverlayDelay.mov

This is my code:

- (void)addCircle
{
    // draw the radius circle for the marker
    double radius = 2000.0;
    MKCircle *circle = [MKCircle circleWithCenterCoordinate:location radius:radius];
    [circle setTitle:@"background"];
    [mapView addOverlay:circle];

    MKCircle *circleLine = [MKCircle circleWithCenterCoordinate:location radius:radius];
    [circleLine setTitle:@"line"];
    [mapView addOverlay:circleLine];
}

- (void)addCircleWithRadius:(double)radius
{
    MKCircle *circle = [MKCircle circleWithCenterCoordinate:location radius:radius];
    [circle setTitle:@"background"];
    [mapView addOverlay:circle];

    MKCircle *circleLine = [MKCircle circleWithCenterCoordinate:location radius:radius];
    [circleLine setTitle:@"line"];
    [mapView addOverlay:circleLine];
}

- (void)sliderChanged:(UISlider*)sender
{
    [mapView removeOverlays:[mapView overlays]];

    double radius = (sender.value * 100);

    [self addCircleWithRadius:radius];
}

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay{
    MKCircle *circle = overlay;
    MKCircleView *circleView = [[[MKCircleView alloc] initWithCircle:overlay] autorelease];

    if ([circle.title isEqualToString:@"background"])
    {
        circleView.fillColor = UIColorFromRGB(0x598DD3);
        circleView.alpha = 0.25;
    }
    else
    {
        circleView.strokeColor = UIColorFromRGB(0x5C8AC7);
        circleView.lineWidth = 2.0;
    }

    return circleView;
}

Does anybody have any suggestions on how I can smoothen this?

Best regards,
Paul Peelen

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have tried your code and found a very easy way to make it smoother.

If you change the order of the calls in: - (void)sliderChanged:(UISlider*)sender

You can call [self addCircleWithRadius:radius];

before calling [mapView removeOverlays:[mapView overlays]];

Just make sure you dont remove the overlays you just added, only the old ones.

This will give you a smoother resizing, specially when the new circle is smaller than the old one.

For circles that are bigger you are probably better off using NSOperations to ensure the views are created faster, this will make it smoother.

Hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...