#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
UIImageView-播放序列图(简单的动画效果实现)
最新推荐文章于 2024-08-16 08:21:02 发布