序列帧动画的实现

序列帧动画的实现_第1张图片
序列帧动画效果图

实现源码:

#import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UIImageView *imageView;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];}//点击view就会调用此方法-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event{

//创建可变数组加载图片

NSMutableArray *arrM=[NSMutableArray array];

//2.for循环添加凭借图片名称并加载图片

for (NSInteger i=0; i<25; i++) {

//3.拼接图片名称

NSString *imageName=[NSString stringWithFormat:@"father%03zd",i+1];

//4.加载图片

UIImage *image=[UIImage imageNamed:imageName];

//5.把图片添加到可变数组保存起来

[arrM addObject:image];

}

//图片拼接成动态图片

UIImage *animationImage=[UIImage animatedImageWithImages:arrM duration:arrM.count*0.2];

self.imageView.image=animationImage;

}

@end


GitHub源码地:https://github.com/KeithBigBather666/-02.git

你可能感兴趣的:(序列帧动画的实现)