UIImageView-播放序列图(简单的动画效果实现)

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIImage *image1 = [UIImage imageNamed:@"weibo"];
    
    // 1.找到文件目录
    NSString *path = [NSString stringWithFormat:@"%@/Untitled-1.fw.png",[[NSBundle mainBundle] resourcePath]];
    NSLog(@"path - %@",path);
    UIImage *image2 = [[UIImage alloc] initWithContentsOfFile:path];
    /**
     如果是用imageNamed方法获取的图片会被缓存在内存中,下一次使用时直接从内存加载不需要再次读取图片,效率非常高,但是会占有一定量的内存。(多次调用的小图片会选择此方法加载)
     initWithContentsOfFile方法是从本地或者网络读取图片文件,但是不加入到缓存中,我们可以手动释放掉,每次加载图片都要读取源文件,所以在读取上效率较低,但是我们可以随时操作内存的释放(当我们要加载高精度大图时使用此方法)
     */
    
    // 载体 - 最基本单元UIImageView
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image1];
    // 显示图片的大小是载体的frame决定的而不是图片本身
    //imageView.frame = CGRectMake(10, 30, image1.size.width, image1.size.height);
    //imageView.center = CGPointMake(320/2, 480/2);
    imageView.frame = CGRectMake(10, 30, 300, 440);
    // 内容模式(UIView属性)
    /**
        UIViewContentModeScaleToFill - 默认状态,改变比例拉伸充满整个载体
        UIViewContentModeScaleAspectFill - 不改变比例缩放充满整个载体,但是由于载体可能跟图片比例不同所以会有超出的一边
        UIViewContentModeScaleAspectFit - 不改变比例缩放充满载体的短边即可,由于载体可能跟图片比例不同所以会有空余的地方。
     */
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    imageView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:imageView];
    
    
    // UIImageView动画(播放序列图)
    // 1.将序列图加入数组
    NSMutableArray *imagesArray = [[NSMutableArray alloc] init];
    for(int i=1;i<=13;i++)
    {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"png%d.png",i]];
        [imagesArray addObject:image];
    }
    UIImageView *imageView1 = [[UIImageView alloc] init];
    imageView1.frame = CGRectMake(10, 200, 300, 217);
    imageView1.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:imageView1];
    // 设置序列图数组
    imageView1.animationImages = imagesArray;
    // 设置播放周期时间
    imageView1.animationDuration = 2;
    // 设置播放次数
    imageView1.animationRepeatCount = 0;
    // 播放动画
    [imageView1 startAnimating];
    //[imageView1 stopAnimating];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值