MKOverlay 无法顺利调整大小

2023-10-03移动开发问题
13

本文介绍了MKOverlay 无法顺利调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已将 MKCircle 作为 MKOverlay 添加到我的 MKMapView.我还添加了一个 UISlider 来决定圆的半径.不幸的是,当使用它时,它似乎有点滞后",不像我想要的那样流畅.

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.

示例:http://dl.dropbox.com/u/3077127/mkoverlayDelay.mov

这是我的代码:

- (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

推荐答案

我已经尝试过你的代码,并找到了一个非常简单的方法来使它更流畅.

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

如果更改调用顺序:- (void)sliderChanged:(UISlider*)sender

你可以调用[self addCircleWithRadius:radius];

调用之前[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.

对于更大的圆圈,您最好使用 NSOperations 以确保更快地创建视图,这将使其更平滑.

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

希望这会有所帮助.

这篇关于MKOverlay 无法顺利调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7