[iOS基础控件 - 3.4] 汤姆猫
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/css/cuteeditor.css);
1 self.tom.animationImages = images; // 存储了多张组成动画的图片
2
3 [self.tom setAnimationRepeatCount:1]; // 默认0是无限次
4 [self.tom setAnimationDuration: images.count/FramesCount];
5 [self.tom startAnimating];
1 // imageNamed: 有缓存
2 // UIImage *image = [UIImage imageNamed:fileName];
3
4 // imageWithContentOfFile: 没有缓存(传入文件的全路径)
5 NSBundle *bundle = [NSBundle mainBundle];
6 NSString *path = [bundle pathForResource:fileName ofType:nil];
7 UIImage *image = [UIImage imageWithContentsOfFile:path];
[self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration + 1];
1 #import "ViewController.h"
2
3 #define FramesCount 24 // 动画帧数/秒
4
5 @interface ViewController ()
6 @property (weak, nonatomic) IBOutlet UIImageView *tom;
7
8 - (IBAction)drink;
9 - (IBAction)knockHead;
10
11 @end
12
13 @implementation ViewController
14
15 - (void)viewDidLoad {
16 [super viewDidLoad];
17 // Do any additional setup after loading the view, typically from a nib.
18
19 }
20
21 - (void)didReceiveMemoryWarning {
22 [super didReceiveMemoryWarning];
23 // Dispose of any resources that can be recreated.
24 }
25
26 /** 点击牛奶按钮 */
27 - (IBAction)drink {
28 [self runAnimationWithName:@"drink" andCount:80];
29 }
30
31 /** 点击头部 */
32 // 实质是在头部放置了一个不带文字的透明按钮
33 - (IBAction)knockHead {
34 [self runAnimationWithName:@"knockout" andCount:80];
35 }
36
37 /** 运行相应动画 */
38 - (void) runAnimationWithName:(NSString *) animationName andCount:(int) count {
39 if (self.tom.isAnimating) return;
40
41 NSMutableArray *images = [NSMutableArray array];
42 for (int i=0; i <= count; i++) {
43 NSString *fileName = [NSString stringWithFormat:@"%@_%02d.jpg", animationName, i];
44
45 // imageNamed: 有缓存
46 // UIImage *image = [UIImage imageNamed:fileName];
47
48 // imageWithContentOfFile: 没有缓存(传入文件的全路径)
49 NSBundle *bundle = [NSBundle mainBundle];
50 NSString *path = [bundle pathForResource:fileName ofType:nil];
51 UIImage *image = [UIImage imageWithContentsOfFile:path];
52
53 [images addObject:image];
54 }
55
56 self.tom.animationImages = images; // 存储了多张组成动画的图片
57
58 [self.tom setAnimationRepeatCount:1]; // 默认0是无限次
59 [self.tom setAnimationDuration: images.count/FramesCount];
60 [self.tom startAnimating];
61
62 [self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration + 1];
63 }
64
65
66 @end
[iOS基础控件 - 3.4] 汤姆猫的更多相关文章
- [iOS基础控件 - 5.5] 代理设计模式 (基于”APP列表"练习)
A.概述 在"[iOS基础控件 - 4.4] APP列表 进一步封装,初见MVC模式”上进一步改进,给“下载”按钮加上效果.功能 1.按钮点击后,显示为“已下载”,并且不 ...
- [UI基础][不会说话的汤姆猫]
会说话的汤姆猫这个APP层级风靡一时,其UI部分就是利用了序列动画的技术, 接下来 我们用汤姆猫来演示怎么制作序列动画. [要求]: 1.学会使用序列动画的方法 2.学会分析动画播放中内存占用高的问题 ...
- iOS 基础控件(下)
上篇介绍了UIButton.UILabel.UIImageView和UITextField,这篇就简短一点介绍UIScrollView和UIAlertView. UIScrollView 顾名思义也知 ...
- [iOS基础控件 - 7.0] UIWebView
A.基本使用 1.概念 iOS内置的浏览器控件 Safari浏览器就是通过UIWebView实现的 2.用途:制作简易浏览器 (1)基本请求 创建请求 加载请求 (2)代理监听webView加载, ...
- [iOS基础控件 - 6.11.3] 私人通讯录Demo 控制器的数据传递、存储
A.需求 1.搭建一个"私人通讯录"Demo 2.模拟登陆界面 账号 密码 记住密码开关 自动登陆开关 登陆按钮 3.退出注销 4.增删改查 5.恢复数据(取消修改) 这个代码 ...
- [iOS基础控件 - 6.10.2] PickerView 自定义row内容 国家选择Demo
A.需求 1.自定义一个UIView和xib,包含国家名和国旗显示 2.学习row的重用 B.实现步骤 1.准备plist文件和国旗图片 2.创建模型 // // Flag.h // Co ...
- [iOS基础控件 - 6.9] 聊天界面Demo
A.需求 做出一个类似于QQ.微信的聊天界面 1.每个cell包含发送时间.发送人(头像).发送信息 2.使用对方头像放在左边,我方头像在右边 3.对方信息使用白色背景对话框,我方信息使用蓝色背景对话 ...
- iOS基础 - 控件属性
一.控件的属性 1.CGRect frame 1> 表示控件的位置和尺寸(以父控件的左上角为坐标原点(0, 0)) 2> 修改这个属性,可以调整控件的位置和尺寸 2.CGPoint cen ...
- [iOS基础控件 - 6.12.3] @property属性 strong weak copy
A.概念 @property 的修饰词 strong: 强指针/强引用(iOS6及之前是retain) weak: 弱智真/弱引用(iOS6及之前是assign) 默认情况所有指针都是强指针 ...
随机推荐
- window下编译ffmpeg 比较简单
网上关于编译ffmpeg的帖子很多,我也尝试了很多次,但是很多都过不了,一部分原因是版本问题,还有就是有的路劲没说的太明白导致的,经过一天的摸索,最终编译好了,下面把编译方式写下来,希望对看到帖子的人 ...
- Sqlmap基础(二)
sqlmap.py -r req1.txt --dbms Oracle --risk
- js动态创建及移除div的方法
本文实例讲述了js动态创建及移除div的方法.分享给大家供大家参考.具体实现方法如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...
- 安装Ubuntu双系统系列——更换源
Ubuntu 有一个非常有用的命令 apt-get,它可以帮助你下载软件,还可以安装,下载并安装的命令是 apt-get install. 那Ubuntu默认是从哪里下载软件呢,这可以查看文件/etc ...
- JVM内存管理(二)
JVM内存管理 JVM在执行java程序的过程中,会把内存划分为若干个不同的数据区域.这些区域都有各自的用途,以及创建和销毁的时间,有的区域随着虚拟机进程的启动而存在,有些区域则依赖 ...
- Flash Builder 4.6 找不到所需的Adobe Flash Player
问题: 安装完Flash Builder 4.6 ,第一次运行项目,出现如下错误提示: “Flash Builder 找不到所需版本的 Adobe Flash Player.您可能需要安装该版本的 F ...
- javeWeb常用快捷键 Junit for changeableargs enumn reflect
*1 工具常用的快捷键 1) Eclipse和MyEclipse,IBM,2001,Java编写,开源,跨平台跨语言 2)Alt+/快速内容提示 3)Ctrl+1快速修补错误 4)Syso ...
- pb 插入控件是出问题
http://m.blog.csdn.net/blog/jqz1225/34417493 是的http://blog.163.com/wufeng_1213/blog/static/167783313 ...
- SQL Server中Delete语句表名不能用别名
delete from TABLEA A where A.FIELD1=10 (ORACLE适用)delete TABLEA from TABLEA A where A.FIELD1=1 ...
- -_-#【Dom Ready / Dom Load】
Dom Ready和Dom Load DOM Ready 详解 javascript的domReady 域名解析 - 加载html - 加载js和css - Dom Ready - 加载图片等其他信息 ...