Wednesday, February 25, 2015

Create animation for set of Images

 // The root view of the view controller set in Interface Builder is a UIImageView.
    UIImageView *imageView = (UIImageView *)self.view;
    imageView.animationImages = @[
                          [UIImage imageNamed:@"image_animal_1"],
                          [UIImage imageNamed:@"image_animal_2"],
                          [UIImage imageNamed:@"image_animal_3"],
                          [UIImage imageNamed:@"image_animal_4"],
                          [UIImage imageNamed:@"image_animal_5"]
    // We want the image to be scaled to the correct aspect ratio within imageView's bounds.
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    // If the image does not have the same aspect ratio as imageView's bounds, then imageView's backgroundColor will be applied to the "empty" space.
    imageView.backgroundColor = [UIColor whiteColor];
    imageView.animationDuration = 5;
    [imageView startAnimating];
    imageView.isAccessibilityElement = YES;

    imageView.accessibilityLabel = NSLocalizedString(@"Animated", nil);

No comments:

Post a Comment