0

I have animation of images and some images are different widths and heights. What I am looking to do is set the width and height to each of theses images.

jumperguy.animationImages = [NSArray arrayWithObjects:
                             [UIImage imageNamed:@"jumperguy_a_1.png"],
                             [UIImage imageNamed:@"jumperguy_a_2.png"],
                             [UIImage imageNamed:@"jumperguy_a_3.png"],
                             [UIImage imageNamed:@"jumperguy_a_4"],nil];

[jumperguy setAnimationRepeatCount:1];
jumperguy.animationDuration = 1;
[jumperguy startAnimating];
rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

0

UIImageView animation does a "flip book" style animation where each image is drawn into the same frame. I don't believe it will handle images of different sizes between frames. As Wain suggests, you should scale your images to fit in the same frame in an image editor before putting them into your app.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
0

As I mentioned in my comment, you can programmatically scale each image in your array like so:

    ...

    CGFloat width = whateverWidth;
    CGFloat height = whateverHeight;
    jumperguy.animationImages = [NSArray arrayWithObjects:
                     [self imageWithImage:[UIImage imageNamed:@"jumperguy_a_1.png"] scaledToSize:CGSizeMake(width, height)],
                     [self imageWithImage:[UIImage imageNamed:@"jumperguy_a_2.png"] scaledToSize:CGSizeMake(width, height)],
                     [self imageWithImage:[UIImage imageNamed:@"jumperguy_a_3.png"] scaledToSize:CGSizeMake(width, height)],
                     [self imageWithImage:[UIImage imageNamed:@"jumperguy_a_4.png"] scaledToSize:CGSizeMake(width, height)],nil];

    [jumperguy setAnimationRepeatCount:1];
    jumperguy.animationDuration = 1;
    [jumperguy startAnimating];

}



- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
    //UIGraphicsBeginImageContext(newSize);
    // In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
    // Pass 1.0 to force exact pixel size.
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return newImage;
}
Lyndsey Scott
  • 37,080
  • 10
  • 92
  • 128