2

OpenGLに入らずに(Quartz 2DはOKです):

  1. 流動的な方法でマップ上を移動したい画像があるとしましょう。たとえば、地図上を「飛んでいる」飛行機の画像。私はこれをMKAnnotation、NSTimerを使用して、緯度/経度の変化率とタイマー率をいじることができました。ただし、結果はかなりまともなように見えますが、これは理想的ではないと思います。もっと良い方法を考えられますか?

  2. ここで、この画像をアニメーション化したいとします(アニメーションGIFを考えてみてください)。MKAnnotationViewでアクセスできるのは。だけなのでUIImageView、一連のシリーズでは通常のことはできません。どうやってこれに取り組むの?animationFramesUIImage

#2は、animationImagesを含むマップの上部にあるUIImageViewで処理できることに気付きました。ただし、実際のユーザーの動きやユーザーのズームに応じて、平面やロケットなどの動きの変換を手動で処理する必要があります(私のアプリではスクロールは許可されていません)。

どう思いますか?

4

1 に答える 1

5

#2の解決策を見つけたと思います。MKAnnotationView をサブクラス化し、UIImageView (アニメーション画像付き) をサブビューとして追加するコードを書きました。

//AnimatedAnnotation.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface AnimatedAnnotation : MKAnnotationView
{
    UIImageView* _imageView;
    NSString *imageName;
    NSString *imageExtension;
    int imageCount;
    float animationDuration;
}

@property (nonatomic, retain) UIImageView* imageView;
@property (nonatomic, retain) NSString* imageName;
@property (nonatomic, retain) NSString* imageExtension;
@property (nonatomic) int imageCount;
@property (nonatomic) float animationDuration;


- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier imageName:(NSString *)name imageExtension:(NSString *)extension imageCount:(int)count animationDuration:(float)duration
;

@end

//AnimatedAnnotation.m

#import "AnimatedAnnotation.h"

@implementation AnimatedAnnotation
@synthesize imageView = _imageView;
@synthesize imageName, imageCount, imageExtension,animationDuration;

- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier imageName:(NSString *)name imageExtension:(NSString *)extension imageCount:(int)count animationDuration:(float)duration
{
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    self.imageCount = count;
    self.imageName = name;
    self.imageExtension = extension;
    self.animationDuration = duration;
    UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@0.%@",name,extension]];
    self.frame = CGRectMake(0, 0, image.size.width, image.size.height);
    self.backgroundColor = [UIColor clearColor];


    _imageView = [[UIImageView alloc] initWithFrame:self.frame];
    NSMutableArray *images = [[NSMutableArray alloc] init];
    for(int i = 0; i < count; i++ ){
        [images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%@%d.%@", name, i, extension]]];
    }


    _imageView.animationDuration = duration;
    _imageView.animationImages = images;
    _imageView.animationRepeatCount = 0;
    [_imageView startAnimating];

    [self addSubview:_imageView];

    return self;
}

-(void) dealloc
{
    [_imageView release];
    [super dealloc];
}


@end
于 2009-08-20T04:42:13.077 に答える