एक MKMapView भर में एक स्प्राइट एनिमेट

वोट
2

ओपन में हो रही बिना (क्वार्ट्ज 2 डी ठीक है):

  1. के मैं एक छवि है जो मुझे कुछ तरल पदार्थ रास्ते में एक नक्शा भर में स्थानांतरित करने के लिए करना चाहते हैं करते हैं। उदाहरण के लिए, एक हवाई जहाज की एक छवि नक्शा भर में उड़ान। मैं इस एक MKAnnotation, एक NSTimer का उपयोग कर और अक्षांश / देशांतर परिवर्तन और टाइमर दर की दर के साथ नगण्य करने के लिए सक्षम किया गया है। हालांकि, मुझे लगता है यह आदर्श नहीं है, हालांकि परिणाम बहुत सभ्य लग रहे हो। आप एक बेहतर तरीका के बारे में सोच सकते हैं?

  2. अब मान लीजिए कि मैं इस छवि एनिमेटेड किया जा करने के लिए (: एनिमेटेड gif लगता है) चाहते हैं। मैं हमेशा की तरह नहीं कर सकते UIImageViewकी एक श्रृंखला के साथ animationFramesसभी क्योंकि मैं करने के लिए MKAnnotationView में एक है उपयोग कर सकते है UIImage। तुम लोग यह कैसे से निपटने के हैं?

मुझे लगता है कि # 2 animationImages युक्त नक्शे के शीर्ष पर एक UIImageView के साथ संभाला जा सकता है। हालांकि, तो मैं मैन्युअल रूप से हवाई जहाज या रॉकेट या जो कुछ भी की आवाजाही के अनुवाद के रूप में MapView के क्षेत्र बदल गया है, वास्तविक दुनिया में उपयोगकर्ता की गतिविधियों पर निर्भर करता है, या उपयोगकर्ता (स्क्रॉल मेरे एप्लिकेशन में अनुमति नहीं है) जूमिंग संभाल करने के लिए होगा।

तुम क्या सोचते हो?

20/08/2009 को 04:06
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


1 जवाब

वोट
5

मुझे लगता है मैं # 2 के लिए एक समाधान खोज निकाला है। मैं MKAnnotationView subclassed और एक subview के रूप एक 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
20/08/2009 को 05:42
का स्रोत उपयोगकर्ता

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