如何使用iPhone SDK为这样的图像制作动画?

时间:2012-06-04 05:10:43

标签: iphone objective-c ios cocoa-touch animation

请检查this app:

该应用程序的屏幕截图如下所示:

enter image description here

请告诉我如何在触摸时添加图片并让每张图片都有动画效果?

1 个答案:

答案 0 :(得分:4)

iOS 5 中,您可以使用一系列图片。首先,您需要添加一个新的类别方法:

分类

@interface UIImage (WrightsCS)
+(UIImage*)animatedImageWithImages:(NSArray*)images duration:(NSTimeInterval)duration;
@end

实施例

+(UIImage*)loadingImage
{
    NSArray *animationFrames = [NSArray arrayWithObjects:
                                        [UIImage imageNamed:@"downloading01.png"],
                                        [UIImage imageNamed:@"downloading02.png"],
                                        [UIImage imageNamed:@"downloading03.png"],
                                        [UIImage imageNamed:@"downloading04.png"],
                                        [UIImage imageNamed:@"downloading05.png"],
                                        [UIImage imageNamed:@"downloading06.png"],
                                        [UIImage imageNamed:@"downloading07.png"],
                                        [UIImage imageNamed:@"downloading08.png"],
                                        [UIImage imageNamed:@"downloading09.png"],
                                        [UIImage imageNamed:@"downloading10.png"],
                                        [UIImage imageNamed:@"downloading11.png"],
                                        [UIImage imageNamed:@"downloading12.png"],
                                        [UIImage imageNamed:@"downloading13.png"],
                                        [UIImage imageNamed:@"downloading14.png"],
                                        [UIImage imageNamed:@"downloading15.png"],
                                        [UIImage imageNamed:@"downloading16.png"],
                                nil];
    return [UIImage animatedImageWithImages:animationFrames duration:1.0f];
}