//
// ViewController.m
// UI02_UIImageView
//
// Created by lanou3g on 17/8/4.
// Copyright © 2017年 lanou3g. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];
// imageView.frame = CGRectMake(100, 100, 100, 100);
// [self.view addSubview:imageView];
NSMutableArray *imageArray = [NSMutableArray array];
for (int i = 0; i <= 21; i++) {
NSString *imageName = [NSString stringWithFormat:@"Zombie%d.tiff",i];
UIImage *image = [UIImage imageNamed:imageName];
[imageArray addObject:image];
}
UIImageView *zombieImageView = [[UIImageView alloc] initWithImage:[imageArray firstObject]];
zombieImageView.frame = CGRectMake(200, 200, 200, 200);
[self.view addSubview:zombieImageView];
//设置播放一组图片
zombieImageView.animationImages = imageArray;
//设置播放一组图片的总时长
zombieImageView.animationDuration = 0.2;
//设置播放一组图片循环次数(0为无限循环)
zombieImageView.animationRepeatCount = 0;
//开始播放
[zombieImageView startAnimating];
//平移动画
[UIView animateWithDuration:5.f animations:^{
zombieImageView.frame = CGRectMake(-200, 100, 200, 200);
}completion:^(BOOL finished) {
[UIView animateWithDuration:5.f animations:^{
zombieImageView.frame = CGRectMake(200, 200, 200, 200);
}];
}];
}
//封装动画方法
- (void)animation:(UIView *)animationView duration:(NSTimeInterval)duration frame:(CGRect)frame {
[UIView animateWithDuration:duration animations:^{
animationView.frame = frame;
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
网友评论