Problem with Array of UIImage

Discussion in 'iOS Programming' started by saimonx, Dec 23, 2010.

  1. saimonx macrumors newbie

    Joined:
    Jan 26, 2009
    Location:
    Almeria, Spain
    #1
    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?
     
  2. MicroApple macrumors regular

    Joined:
    Jul 26, 2010
    #2
    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.
     
  3. saimonx thread starter macrumors newbie

    Joined:
    Jan 26, 2009
    Location:
    Almeria, Spain
    #3
    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???
     
  4. wlh99 macrumors 6502

    Joined:
    Feb 7, 2008
    #4
    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.
     

Share This Page