Animacji sprite całej MKMapView

głosy
2

Bez wchodzenia w OpenGL (Quartz 2D jest OK):

  1. Powiedzmy, że mam obraz, który chcę, aby poruszać się po mapie w jakiś sposób płynów. Na przykład obraz z samolotu „pływa” po mapie. Byłem w stanie to zrobić przy użyciu MKAnnotation An NSTimer i błahy z szybkością łac Zmień / lon i szybkości zegara. Jednak zakładam ten nie jest idealny, choć wyniki wyglądają całkiem przyzwoicie. Czy można sobie wyobrazić lepszy sposób?

  2. Teraz załóżmy, że chcę ten obraz ma być animowany (myślę: animowany gif). Nie mogę tego zrobić zwykły UIImageViewz serii animationFrames, ponieważ wszystko, co mają dostęp do w MKAnnotationView jest UIImage. Jak wy uporać się z tym?

Zdaję sobie sprawę, że nr 2 mogą być obsługiwane z UIImageView na górze mapy zawierającej animationImages. Jednak wtedy będę musiał ręcznie obsługiwać tłumaczenia ruch samolotu lub rakiety lub cokolwiek jako rejon MapView zmianie, w zależności od ruchów użytkownika w świecie rzeczywistym, lub powiększanie użytkownika (przewijanie nie jest dozwolone w mojej aplikacji).

Co myślisz?

Utwórz 20/08/2009 o 04:06
źródło użytkownik
W innych językach...                            


1 odpowiedzi

głosy
5

Myślę, że zorientowali się rozwiązanie # 2. I podklasy MKAnnotationView i napisał jakiś kod, aby dodać UIImageView (z obrazów animowanych) jako podrzędny.

//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
Odpowiedział 20/08/2009 o 05:42
źródło użytkownik

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more