0

MKMapViewでレーダー画像をアニメーション化しようとしています。異なる時間に別々の画像があり、MKMapViewの上にオーバーレイとして画像を設定することに成功しました。私の問題は、これらの異なる画像を次々に順番に表示しようとするときです。オーバーレイを追加および削除する方法を試しましたが、システムがそれをまったく処理せず、オーバーレイがちらつき、一部のオーバーレイが削除されず、全体として価値がありません。

MapViewの上に複数の画像(アニメーションGIFなど)をスムーズかつ高速に表示する方法を見つけるのを手伝ってくれる人はいますか?

画像をオーバーレイするための私のコードは次のとおりです。

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

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 {
    }

}

オーバーレイを追加する場所は次のとおりです。

- (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に一連の画像をスムーズに表示できるアイデアや解決策はありますか?この時点で、私は解決策を切望していて、他のどこにもそれを見つけることができないので、何かが私を助けてくれるでしょう、ありがとう!

4

1 に答える 1

1

Lefterisの提案を使用すると、animationImagesでUIImageViewを使用できます。オーバーレイ画像が画面に対して適切なサイズである場合、アニメーションはスムーズである必要があります。

以下のマップビューにタッチを渡すために、マップビューへの(弱い)参照を使用して新しいUIViewサブクラスを作成できます。次のように、タッチイベントメソッド(touchesBegan:withEvent:、touchesMoved:withEvent:など)をオーバーライドして、マップビューに転送します。

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

このようにして、ユーザーは引き続き下のビューを操作できます。

すべてのアニメーションフレームをリアルタイムで拡大縮小することは不可能ではないにしても困難であるため、ユーザーがズームしようとすると問題が発生する可能性があります。代わりにCATiledLayerの使用を検討する必要があります。

于 2013-01-16T19:24:33.860 に答える