Animálása sprite egy egész MKMapView

szavazat
2

Anélkül, hogy az OpenGL (Quartz 2D OK):

  1. Tegyük fel, hogy van egy kép, amit szeretnék, hogy mozog a térképet valamilyen folyadék módon. Például, egy kép egy sík „repülő” az egész térképet. Voltam képes megtenni ezt, ha az MKAnnotation egy NSTimer és hegedülő az arány lat / lon változás és az időmérőt arány. Azonban Feltételezem, hogy ez nem ideális, bár az eredmények meg elég tisztességes. Tudna egy jobb út?

  2. Most mondjuk, hogy akarom ezt a képet, hogy animált (gondolom: animált gif). Nem tudok a szokásos UIImageViewegy sor animationFrames, mert én férnek hozzá a MKAnnotationView egy UIImage. Hogyan srácok megoldani ezt?

Rájöttem, hogy a # 2 lehet kezelni egy UIImageView tetején a térképet tartalmazó animationImages. Azonban akkor azt kézzel kell kezelni fordítására mozgását a sík vagy a rakéta, vagy bármi, mint a régióban a mapview változott, attól függően, hogy a felhasználó mozgását a valós, vagy a felhasználó zoom (görgetés nem megengedett az én app).

Mit gondolsz?

A kérdést 20/08/2009 04:06
a forrás felhasználó
Más nyelveken...                            


1 válasz

szavazat
5

Azt hiszem, kitalálta a megoldást: # 2. Azt subclassed MKAnnotationView és írt néhány kódot hozzá egy UIImageView (animációs képek) a subview.

//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
Válaszolt 20/08/2009 05:42
a forrás felhasználó

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