Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

saimonx

macrumors newbie
Original poster
Jan 26, 2009
6
0
Almeria, Spain
Hi!!

I have a compatibility problem with my iPhone project.

I am using an external iPhone API, and i have the following code to add a marker to a map:

Code:
RMMarker *newMarker;
UIImage *blueMarkerImage = [UIImage imageNamed:@"marker.png"];
newMarker = [[RMMarker alloc] initWithUIImage:blueMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];


[mapView.contents.markerManager addMarker:newMarker AtLatLong:position];
[newMarker release];

Ok, this goes well, but i want to make a little change.

I want to add an animated marker to the map instead to add a simple image.

I have seen this implementation:
Code:
NSArray *myImages = [NSArray arrayWithObjects:
    [UIImage imageNamed:@"myImage1.png"],
    [UIImage imageNamed:@"myImage2.png"],
    [UIImage imageNamed:@"myImage3.png"],
    [UIImage imageNamed:@"myImage4.gif"],
    nil];

UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 0.25; // seconds
myAnimatedView.animationRepeatCount = 0; // 0 = loops forever
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[myAnimatedView release];

The problem is that "initWithUIImage:" only accept UIImage.

So, how can i add an animated image here?
 
http://developer.apple.com/library/...erence/UIImage_Class/Reference/Reference.html

The documentation for the UIImage class says it supports GIF images, a simple way to do this is just to compile all those images into an animated GIF and then give that to the UIImage class.

Note:
*GIFs usually lower the quality of images from PNG->GIF so you should rework it if it looks to strange, but usually for an image that small like a map marker it should be fine.

*I'm also assuming iOS's UIImage class supports animated GIF's my guess is that they do but you can test it out.
 
http://developer.apple.com/library/...erence/UIImage_Class/Reference/Reference.html

The documentation for the UIImage class says it supports GIF images, a simple way to do this is just to compile all those images into an animated GIF and then give that to the UIImage class.

Note:
*GIFs usually lower the quality of images from PNG->GIF so you should rework it if it looks to strange, but usually for an image that small like a map marker it should be fine.

*I'm also assuming iOS's UIImage class supports animated GIF's my guess is that they do but you can test it out.
Thanks MicroApple, but no. It seems that only support static gifs, because nothing is showed. Also, when I import it to Xcode, it shows the static image.

Any other idea???
 
The problem is that "initWithUIImage:" only accept UIImage.

So, how can i add an animated image here?

See the UIImageView documentation. There is a task that describes animation.

initWithImage with a single UIImage you want displayed before the animation loads.

Create an NSArray of UIImages of the animation.

Set the animationImages property of the UIImageView to the array.

call the startAnimating method of the UIImageView.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.