的MKMapView叠加(动漫形象) [英] MKMapView Overlay (image animation)

查看:226
本文介绍了的MKMapView叠加(动漫形象)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图动画上的MKMapView雷达图像。我有不同的时间不同的图像,我已经成功地将图像设置为上的MKMapView上重叠。我的问题是,当我尝试后,对方序列中的一个,以显示这些不同的图像。我尝试添加和删除叠加的方法,但系统不都应付自如,具有覆盖的闪烁,有的覆盖不被删除,总体而言,它不值得。

I'm trying to animate a radar image on an MKMapView. I have separate images for different times, and I have successfully set an image as an overlay on top of the MKMapView. My problem is when I try to show these different images in a sequence one after each other. I tried a method of adding and removing overlays, but the system does not handle it well at all, with flickering of overlays, and some overlays not being removed, and overall, its not worth it.

谁能帮我找到一种方式来显示一个图形页面的多张图像(如GIF动画)的方式,流畅和快速的?

Could anyone help me find a way to show multiple images (like an animated gif) on top of a MapView in a way that is smooth and fast?

下面是我的code叠加图像:

Here's my code to overlay the image:

- (id)initWithImageData:(NSData*)imageData withLowerLeftCoordinate:(CLLocationCoordinate2D)lowerLeftCoordinate withUpperRightCoordinate:(CLLocationCoordinate2D)upperRightCoordinate {

self.radarData = imageData;

MKMapPoint lowerLeft = MKMapPointForCoordinate(lowerLeftCoordinate);
MKMapPoint upperRight = MKMapPointForCoordinate(upperRightCoordinate);

mapRect = MKMapRectMake(lowerLeft.x, upperRight.y, upperRight.x - lowerLeft.x, lowerLeft.y - upperRight.y);

return self;

}

- (CLLocationCoordinate2D)coordinate
{
    return MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMidX(mapRect), MKMapRectGetMidY(mapRect)));
}

- (MKMapRect)boundingMapRect
{
    return mapRect;
}

和这里就是我如何设置它的图形页面:

and here's how I'm setting it up on the MapView:

- (void)drawMapRect:(MKMapRect)mapRect
          zoomScale:(MKZoomScale)zoomScale
          inContext:(CGContextRef)ctx
{
    MapOverlay *mapOverlay = (MapOverlay *)self.overlay;
    image = [[UIImage alloc] initWithData:mapOverlay.radarData];

    MKMapRect theMapRect = [self.overlay boundingMapRect];
    CGRect theRect = [self rectForMapRect:theMapRect];


    @try {
        UIGraphicsBeginImageContext(image.size);
        UIGraphicsPushContext(ctx);
        [image drawInRect:theRect blendMode:kCGBlendModeNormal alpha:0.5];
        UIGraphicsPopContext();
        UIGraphicsEndImageContext();
    }
    @catch (NSException *exception) {
        NSLog(@"Caught an exception while drawing radar on map - %@",[exception description]);
    }
    @finally {
    }

}

和这里的地方,我将叠加层:

and here's where I'm adding the overlay:

- (void)mapRadar {        

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

self.mapOverlay = [[MapOverlay alloc] initWithImageData:appDelegate.image withLowerLeftCoordinate:CLLocationCoordinate2DMake(appDelegate.south, appDelegate.west) withUpperRightCoordinate:CLLocationCoordinate2DMake(appDelegate.north, appDelegate.east)];

[self.mapView addOverlay:self.mapOverlay];
[self.mapView setNeedsDisplay];

self.mapView.showsUserLocation = YES;
MKMapPoint lowerLeft2 = MKMapPointForCoordinate(CLLocationCoordinate2DMake(appDelegate.south2, appDelegate.west2) );
MKMapPoint upperRight2 = MKMapPointForCoordinate(CLLocationCoordinate2DMake(appDelegate.north2, appDelegate.east2));

MKMapRect localMapRect = MKMapRectMake(lowerLeft2.x, upperRight2.y, upperRight2.x - lowerLeft2.x, lowerLeft2.y - upperRight2.y);


[self.mapView setVisibleMapRect:localMapRect animated:YES];
}

#pragma Mark - MKOverlayDelgateMethods

-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay{
    if([overlay isKindOfClass:[MapOverlay class]]) {
        MapOverlay *mapOverlay = overlay;
        self.mapOverlayView = [[MapOverlayView alloc] initWithOverlay:mapOverlay];
    }
    return self.mapOverlayView;
}

有没有人有一个想法或一个解决方案,我可以显示上的MKMapView平稳的图像序列?在这一点上,我很绝望的解决方案,并不能找到任何其他地方,所以任何能帮助我,谢谢!

Does anyone have an idea or a solution where I can show a sequence of images on an MKMapView smoothly? At this point, I'm desperate for solutions and can't find it anywhere else, so anything would help me, thanks!

推荐答案

使用Lefteris'的建议,你可以用用的UIImageView animationImages。动画应提供流畅的叠加图像尺寸是否适合屏幕。

Using Lefteris' suggestion, you can just use UIImageView with animationImages. The animation should be smooth provided your overlay images are properly sized for the screen.

要通过下面的地图视图通过触摸,您可以创建一个新的UIView子类具有(弱)参照地图视图。重写<一个href=\"http://developer.apple.com/library/ios/documentation/uikit/reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/instm/UIResponder/touchesBegan%3awithEvent%3a\"相对=nofollow>触摸事件方法(的touchesBegan:withEvent:,touchesMoved:withEvent:等)转发到地图视图,像这样:

To pass touches through to the map view below, you can create a new UIView subclass with a (weak) reference to the map view. Override the touch event methods (touchesBegan:withEvent:, touchesMoved:withEvent:, etc) to forward to the map view, like so:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.mapView touchesBegan:touches withEvent:event];
}

这样,用户仍然可以与下面的观点进行互动。

This way the user can still interact with the view below.

当用户试图放大你可能会碰到的问题,因为这将是困难的,如果不是不可能按比例实时所有的动画帧。你应该考虑使用CATiledLayer来代替。

You may run into problems when the user tries to zoom, as it will be difficult if not impossible to scale all your animation frames in real-time. You should look into using CATiledLayer instead.

这篇关于的MKMapView叠加(动漫形象)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆