/**
图片的两种加载方式:
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. HDU_3172_带权并查集

    Virtual Friends Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  2. arx代码片段

    ObjectARX代码片段二   转载自网络 一  在ARX中禁用AutoCAD的某个命令 以LINE命令为例,在程序中加入下面的一句即可禁用LINE命令: acedCommand(RTSTR, &q ...

  3. moongoTemplate使用

          添加依赖   <dependency> <groupId>org.springframework.boot</groupId> <artifact ...

  4. HEVC-HM16.9源码学习(1)TEncCu::xCompressCU

    函数入口:Void TEncSlice::compressSlice的m_pcCuEncoder->compressCtu( pCtu );调用xCompressCU( m_ppcBestCU[ ...

  5. UVA - 1611 Crane (思路题)

    题目: 输入一个1~n(1≤n≤300)的排列,用不超过96次操作把它变成升序.每次操作都可以选一个长度为偶数的连续区间,交换前一半和后一半.输出每次操作选择的区间的第一个和最后一个元素. 思路: 注 ...

  6. docker 部署spring.boot项目【一】(引用外部配置文件)

    上一篇随笔,nginx是启动运行在容器内,spring.boot的web项目是运行在宿主内,这一篇的目的,是把web项目也制作成镜像,然后在容器里启动. 文件目录结构如下: 主要文件结构说明:(1)b ...

  7. 集合:Iterator

    why ? when ? how ? what ? 为什么需要集合呢? 在数据结构中链表.树.堆等一些操作都是由我们自己写的,这些操作是不是可以提取出来,以后要用就直接拿来用就好,这样非常方便. Ja ...

  8. 嵌入式LinuxC语言程序设计基础教程

    第1章 嵌入式LinxuC语言开发工具 第2章 数据 第3章 数据的输入输出 第4章 运算符和表达式 第5章 程序结构和控制语句 第6章 数组 第7章 指针 第8章 函数 第9章 用户自定义数据类型 ...

  9. Spring整合Junit框架

    一.开发环境 eclipse版本:4.6.1 maven版本:3.3.3 junit版本:4.12 spring版本:4.1.5.RELEASE JDK版本:1.8.0_111 二.项目结构 图 三. ...

  10. 利用tempalte.js模版引擎渲染页面,作对应的数据处理

    需要启个服务 需引入jquery.js和template.js <!DOCTYPE html> <html lang="en"> <head> ...