[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) 默认情况所有指针都是强指针 ...
随机推荐
- IText 生成横向的doc文档
IText生成doc文档需要三个包:iTextAsian.jar,iText-rtf-2.1.4.jar,iText-2.1.4.jar 亲测无误,代码如下: import com.lowagie.t ...
- linux命令补全 忘记命令只记得开头
linux的shell不仅提供上下箭头来翻阅历史使用过的命令,还提供命令补全功能. 例如,你想创建一个文件夹,只记得是m开头的命令,此时可以: ①输入m ②按键盘上的Tab键两次 (有可能还出现这句话 ...
- [模拟]ZOJ3485 Identification Number
题意:给了一串15位或18位的身份证号码,求 在改变最少位数的情况下, 输出正确合法的身份证号 合法的身份证 是按照以下规则: 前6位以及“Order code”三位 一定合法 其中X是根据前17位 ...
- undefined与null的区别---js
不错... http://www.ruanyifeng.com/blog/2014/03/undefined-vs-null.html
- HeadFirst设计模式之命令模式
一. 1.因为是操作经常变化,所以封装操作为command对象.You can do that by introducing “command objects” into your design. A ...
- Java API ——StringBuffer类
1.StringBuffer类概述 1)我们如果对字符串进行拼接操作,每次拼接,都会构建一个新的String对象,既耗时,又浪费空间.而StringBuffer就可以解决这个问题 2)线程安全的可变字 ...
- R语言学习笔记:向量化
R语言最强大的方面之一就是函数的向量化,这些函数可以直接对向量的每个元素进行操作.例如: 对每个元素进行开方 > v<-c(4,3,8,16,7.3) > v [1] 4.0 3 ...
- IIS7 发布mvc3.0
Windows7系统和我们见面已经有一段时间了,在我们经过一段时间熟悉了她的新鲜好玩儿的功能之后,也许我们该静下心来想一下怎么用她做一些与学习有 关的事情,从Windows7的第一个试用版到现在的零售 ...
- Android开发之多媒体编程之获取图片的副本
使用BitmapFactory的decodeFile()方法获取的Bitmap对象是只读的,无法进行编辑操作 需要进行编辑的话,需要获取到该对象的一个副本 代码如下: import android.a ...
- Python中的函数对象与闭包
函数在Python中是第一类对象,可以当做参数传递给其他函数,放在数据结构中,以及作为函数的返回结果. 下面的例子为接受另外一个函数作为输入并调用它 #foo.py def callf(func): ...