/**
图片的两种加载方式:
1> imageNamed:
a. 就算指向它的指针被销毁,该资源也不会被从内存中干掉,
b. 放到Assets.xcassets的图片,默认就有缓存,
c. 图片经常被使用,用这种方式加载, 2> imageWithContentsOfFile:
a. 指向它的指针被销毁,该资源会被从内存中干掉,
b. 放到项目中的图片就不带缓存,
c. 不经常用,大批量的图片,使用这种方式, */

/**
* 游戏结束
*/
- (IBAction)gameOver { //没有强指针,就把图片释放了,即使是图片数组,只要把图片数组的首地址置位nil,数组就释放了,所以只要首地址置位nil就可以
self.standImages = nil;
self.smallImages = nil;
self.bigImages = nil; self.imageView.animationImages = nil;
}

//
// ViewController.m
// 07-拳皇动画(加载图片)
// #import "ViewController.h" @interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView; /** 站立 */
@property (nonatomic, strong) NSArray *standImages; //不是故事板上的东西,没有强引用指向,所以这里用strong,
/** 小招 */
@property (nonatomic, strong) NSArray *smallImages;
/** 大招 */
@property (nonatomic, strong) NSArray *bigImages; @end @implementation ViewController // 初始化一些数据
- (void)viewDidLoad {
[super viewDidLoad]; // 1.加载所有的站立图片
self.standImages = [self loadAllImagesWithimagePrefix:@"stand" count:]; // 2.加载所有的小招图片
self.smallImages = [self loadAllImagesWithimagePrefix:@"xiaozhao3" count:]; // 3.加载所有的大招图片
self.bigImages = [self loadAllImagesWithimagePrefix:@"dazhao" count:]; // 4.站立
[self stand];
} /**
* 加载所有的图片
*
* @param imagePrefix 名称前缀
* @param count 图片的总个数
*/
- (NSArray *)loadAllImagesWithimagePrefix:(NSString *)imagePrefix count:(int)count{
NSMutableArray<UIImage *> *images = [NSMutableArray array];
for (int i=; i<count; i++) {
// 获取所有图片的名称
NSString *imageName = [NSString stringWithFormat:@"%@_%d",imagePrefix, i+];
// 创建UIImage
UIImage *image = [UIImage imageNamed:imageName];
// 装入数组
[images addObject:image];
}
return images;
} /**
* 站立
*/
- (IBAction)stand {
// 2.设置动画图片
self.imageView.animationImages = self.standImages; // 3.设置播放次数
self.imageView.animationRepeatCount = ; // 4.设置播放的时长
self.imageView.animationDuration = 0.6; // 5.播放
[self.imageView startAnimating];
} /**
* 小招
*/
- (IBAction)smallZhao {
// 2.设置动画图片
self.imageView.animationImages = self.smallImages; // 3.设置动画次数
self.imageView.animationRepeatCount = ; // 4.设置播放时长
self.imageView.animationDuration = 1.5; // 5.播放
[self.imageView startAnimating]; // 6.站立(延迟),执行一个方法,传入参数,延迟多长时间,
// Selector 方法
// Object 参数
// afterDelay 时间
// NSSelectorFromString(NSString * _Nonnull aSelectorName) 效果一样
[self performSelector:@selector(stand) withObject:nil afterDelay:self.imageView.animationDuration]; } /**
* 大招
*/
- (IBAction)bigZhao {
// 2.设置动画图片
self.imageView.animationImages = self.bigImages; // 3.设置动画次数
self.imageView.animationRepeatCount = ; // 4.设置播放时长
self.imageView.animationDuration = 2.5; // 5.播放
[self.imageView startAnimating]; // 6.站立
[self performSelector:@selector(stand) withObject:nil afterDelay:self.imageView.animationDuration];
} @end
//
// ViewController.m
// 07-拳皇动画(加载图片)
// #import "ViewController.h" @interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView; /** 站立 */
@property (nonatomic, strong) NSArray *standImages;//不是故事板上的东西,没有强引用指向,所以这里用strong,
/** 小招 */
@property (nonatomic, strong) NSArray *smallImages;
/** 大招 */
@property (nonatomic, strong) NSArray *bigImages; @end @implementation ViewController /**
图片的两种加载方式:
1> imageNamed:
a. 就算指向它的指针被销毁,该资源也不会被从内存中干掉,
b. 放到Assets.xcassets的图片,默认就有缓存,
c. 图片经常被使用,用这种方式加载, 2> imageWithContentsOfFile:
a. 指向它的指针被销毁,该资源会被从内存中干掉,
b. 放到项目中的图片就不带缓存,
c. 不经常用,大批量的图片,使用这种方式, */ // 初始化一些数据
- (void)viewDidLoad {
[super viewDidLoad]; // 1.加载所有的站立图片
self.standImages = [self loadAllImagesWithimagePrefix:@"stand" count:]; // 2.加载所有的小招图片
self.smallImages = [self loadAllImagesWithimagePrefix:@"xiaozhao3" count:]; //不需要写外层文件夹的名字,只需要写图片文件的名字即可。 // 3.加载所有的大招图片
self.bigImages = [self loadAllImagesWithimagePrefix:@"dazhao" count:]; // 4.站立
[self stand];
} /**
* 加载所有的图片
*
* @param imagePrefix 名称前缀
* @param count 图片的总个数
*/
- (NSArray *)loadAllImagesWithimagePrefix:(NSString *)imagePrefix count:(int)count{
NSMutableArray<UIImage *> *images = [NSMutableArray array];
for (int i=; i<count; i++) {
// 获取所有图片的名称
NSString *imageName = [NSString stringWithFormat:@"%@_%d",imagePrefix, i+];
// 创建UIImage
// UIImage *image = [UIImage imageNamed:imageName];
NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
// 装入数组
[images addObject:image];
}
return images;
} /**
* 站立
*/
- (IBAction)stand {
/*
// 2.设置动画图片
self.imageView.animationImages = self.standImages; // 3.设置播放次数
self.imageView.animationRepeatCount = 0; // 4.设置播放的时长
self.imageView.animationDuration = 0.6; // 5.播放
[self.imageView startAnimating];
*/
[self palyZhaoWithImages:self.standImages count: duration:0.6 isStand:YES];
} /**
* 小招
*/
- (IBAction)smallZhao {
/*
// 2.设置动画图片
self.imageView.animationImages = self.smallImages; // 3.设置动画次数
self.imageView.animationRepeatCount = 1; // 4.设置播放时长
self.imageView.animationDuration = 1.5; // 5.播放
[self.imageView startAnimating]; // 6.站立(延迟)
[self performSelector:@selector(stand) withObject:nil afterDelay:self.imageView.animationDuration];
*/
[self palyZhaoWithImages:self.smallImages count: duration:1.5 isStand:NO];
} /**
* 大招
*/
- (IBAction)bigZhao {
/*
// 2.设置动画图片
self.imageView.animationImages = self.bigImages; // 3.设置动画次数
self.imageView.animationRepeatCount = 1; // 4.设置播放时长
self.imageView.animationDuration = 2.5; // 5.播放
[self.imageView startAnimating]; // 6.站立
[self performSelector:@selector(stand) withObject:nil afterDelay:self.imageView.animationDuration];
*/
[self palyZhaoWithImages:self.bigImages count: duration:2.5 isStand:NO];
} /**
* 游戏结束
*/
- (IBAction)gameOver { //没有强指针,就把图片释放了,即使是图片数组,只要把图片数组的首地址置位nil,数组就释放了,所以只要首地址置位nil就可以
self.standImages = nil;
self.smallImages = nil;
self.bigImages = nil; self.imageView.animationImages = nil;
} /**
* 放招
*
* @param images 图片数组
* @param count 播放次数
* @param duration 播放时间
* @param isStand 是否站立
*/
- (void)palyZhaoWithImages:(NSArray *)images count: (NSInteger)count duration:(NSTimeInterval)duration isStand:(BOOL)isStand{
// 1.设置动画图片
self.imageView.animationImages = images; // 2.设置动画次数
self.imageView.animationRepeatCount = count; // 3.设置播放时长
self.imageView.animationDuration = duration; // 4.播放
[self.imageView startAnimating]; // 5.站立
if (!isStand) {
[self performSelector:@selector(stand) withObject:nil afterDelay:self.imageView.animationDuration];
}
} @end

/**
图片的两种加载方式:
1> imageNamed:
a. 就算指向它的指针被销毁,该资源也不会被从内存中干掉,
b. 放到Assets.xcassets的图片,默认就有缓存,
c. 图片经常被使用,用这种方式加载, 2> imageWithContentsOfFile:
a. 指向它的指针被销毁,该资源会被从内存中干掉,
b. 放到项目中的图片就不带缓存,
c. 不经常用,大批量的图片,使用这种方式, */
/**
* 游戏结束
*/
- (IBAction)gameOver { //没有强指针,就把图片释放了,即使是图片数组,只要把图片数组的首地址置位nil,数组就释放了,所以只要首地址置位nil就可以
self.standImages = nil;
self.smallImages = nil;
self.bigImages = nil; self.imageView.animationImages = nil;
}

ios10--拳皇动画的更多相关文章

  1. IOS之UIImageView--小实例项目--带音效的拳皇动画

    内容大纲: 1.初步工作 2.开始敲代码 3.注意 4.可能遇到的错误 5.设置音频速率在代码顺序上的注意点 带音效的拳皇动画实例项目 初步工作 1.新建一Objective-C工程之后,将需要的拳皇 ...

  2. [Animations] 快速上手 iOS10 属性动画

    概述 今天要说的UIViewPropertyAnimator, 是iOS10新的API 详细 代码下载:http://www.demodashi.com/demo/10639.html 基础动画, 核 ...

  3. iOS10新特性

    1.Siri API 的开放自然是 iOS 10 SDK 中最激动人心也是亮眼的特性.Apple 加入了一套全新的框架 Intents.framework 来表示 Siri 获取并解析的结果. 在 i ...

  4. ios10 safari 的坑!

    | 导语 ios10 的safari,又给前端开发者挖坑了..测试验证此问题只出现在ios10 safari中.想早点知道结论的,可以直接看最后一个结论~因为,解决过程不重要! 个人原创,未经允许,禁 ...

  5. iOS10 UI设计基础教程

    iOS10 UI设计基础教程 介绍:本教程针对iOS初级开发人员,基于iOS 10系统,使用Swift 3.0语言讲解如何进行UI设计.本教程内容涵盖UI基础构成.UI元素.自动布局.自适应UI.UI ...

  6. ios9和ios10的新特性

    昨天面试了一个做ios开发的公司,其中面试官问我最新的ios系统版本是多少,以及它的特性是什么?由于自己是初学者,所以对这些没有关注过.今天特地搜索了一下关于ios9和ios10的新特性,并整理了一下 ...

  7. WDC2106 iOS10新特性及开发者要注意什么

    昨晚苹果在旧金山召开了WWDC,看了WWDC2016直播,我们发现变得谨慎而开放的苹果在新一版四大平台系统中展示了很多变化,当然重中之重还是伟大的iOS.通过试用iOS10beta版,除了长大了的更强 ...

  8. 推送通知/传感器/UIDynamic仿真(推送通知已适配iOS10)

    推送通知/传感器/UIDynamic 一.推送通知 1.推送通知简介 什么是推送通知 此处的推送通知与NSNotification没有任何关系 可以理解为,向用户推送一条信息来通知用户某件事情 作用: ...

  9. iOS10 CAAnimationDelegate的适配

    最近在xcode8打开之前的动画代码,看到如下警告

  10. iOS10软件崩溃 Xcode8崩溃 打印/字体等问题汇总 韩俊强的博客

    每日更新关注:http://weibo.com/hanjunqiang  新浪微博!iOS开发者交流QQ群: 446310206 [1].Xcode8代码出现ubsystem: com.apple.U ...

随机推荐

  1. (转)Hibernate框架基础——映射集合属性

    http://blog.csdn.net/yerenyuan_pku/article/details/52745486 集合映射 集合属性大致有两种: 单纯的集合属性,如像List.Set或数组等集合 ...

  2. TCP端口状态LISTENING ESTABLISHED CLOSE_WAIT TIME_WAIT SYN_SENT

    TCP状态转移要点 TCP协议规定,对于已经建立的连接,网络双方要进行四次握手才能成功断开连接,如果缺少了其中某个步骤,将会使连接处于假死状态,连接本身占用的资源不 会被释放.网络服务器程序要同时管理 ...

  3. JAVA基础——异常--解析

      简介 异常处理是java语言的重要特性之一,<Three Rules for effective Exception Handling>一文中是这么解释的:它主要帮助我们在debug的 ...

  4. Autolayout性能优化

    客户的需求就是我们进步的动力.最近有客户提出大数据量Topo图的自动布局问题,在Topo中除了Node.Link,还包括Group.Subnetwork等容器组件.在这样的情况下,我们抛开布局算法不谈 ...

  5. World Cup(The 2016 ACM-ICPC Asia China-Final Contest dfs搜索)

    题目: Here is World Cup again, the top 32 teams come together to fight for the World Champion. The tea ...

  6. CQOI2007 涂色 paint (区间dp)

    听说这道题是当年省选题 于是兴致勃勃拿来做了做 至于如何想到思路... 事实上没想象中那么简单... 脑阔挺疼的... (一开始都没看出来是区间dp) 想到可以区间dp,然后就似乎没啥大问题 枚举区间 ...

  7. Java:冒泡排序 | 二分查找

    2018-10-29 20:16:46 冒泡排序 例子(对数字排序): 假设有这样一组数字:32, 8, 128, 2, 64 现在对其进行冒泡排序(*表示下次比较的开始数字): 32>8? t ...

  8. Xshell(smarTTY)连接Linux虚拟机失败(未开放22端口)解决办法

    1.关闭防火墙: 命令:sudo ufw disable 2.安装openssh-server以及openssh-client: 命令:sudo apt-get install openssh-ser ...

  9. Django DTL模板语法中的循环的笔记

    for...in...笔记: for...in...标签: for...in...类似于Python中的for...in....可以遍历列表.元组.字符串.字典等一切可以遍历的对象.示例代码如下: { ...

  10. 解决maven无法加载本地lib/下的jar包问题(程序包XXX不存在)

    这次一个项目用到maven编译,我在本地开发的时候jar包都是放在WEB-INF/lib目录下,通过 BuildPath将jar包导入,然后用MyEclipse中的:maven package命令打成 ...