[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) 默认情况所有指针都是强指针 ...
随机推荐
- [itint5]直角路线遍历棋盘
http://www.itint5.com/oj/#22 这题一开始直接用暴力的DFS来做,果然到25的规模就挂了. vector<bool> visited(50, false); ve ...
- uEditor独立图片上传
项目中.上传图片,非常希望有一款比较兼容的查件. 网上找了一些,图片上传立刻显示的js代码,还有uploadify.都会碰到这样那样的不兼容和其它头疼的问题. 后来想,干脆就用php的上传类最干脆.但 ...
- H264码流解析及NALU
ffmpeg 从mp4上提取H264的nalu http://blog.csdn.net/gavinr/article/details/7183499 639 /* bitstream fil ...
- Linux用户空间与内核空间
源:http://blog.csdn.net/f22jay/article/details/7925531 Linux 操作系统和驱动程序运行在内核空间,应用程序运行在用户空间,两者不能简单地使用指针 ...
- php cloure闭包
Closures 它可以让您创建in-line 函数.许多语言已经开始有此功能了,也许您在不知道的情况下也使用过它. 例如: <?php $myFunction = function() { e ...
- 一步一步制作yaffs/yaffs2根文件系统(二)---安装BusyBox,构造/bin、/sbin、/usr、linuxr
开发环境:Ubuntu 12.04 开发板:mini2440 256M NandFlash 64M SDRAM 交叉编译器:arm-linux-gcc 4.4.3点此可下载 BusyBox版本: ...
- The document has been modified outside of Code Composer. Would you like to reload the file
2013-06-20 10:03:32 烧写过程是合众达给出的文档 problem: I'm new to using Code Composer Studio 3.3 and am having a ...
- Android 签名(1)为什么要签名
所有的应用程序都必须有数字证书,Android系统不会安装一个没有数字证书的应用程序 签名可以: 1,用特权,2完整性鉴别,3安全保证, 1,专用权限或特权要签名 一些特权要经签名才允许.签名可用:S ...
- 【HDOJ】4347 The Closest M Points
居然是KD解. /* 4347 */ #include <iostream> #include <sstream> #include <string> #inclu ...
- Compass 编译.scss文件的问题
compass 命令编译scss文件存在一个问题: 不能对"_"下划线开头的scss文件名称的文件进行编译.将"_"去掉就可以啦