[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) 默认情况所有指针都是强指针 ...
随机推荐
- 选择排序的openMP实现
// test.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdio.h> #include < ...
- [Unity菜鸟] 术语
HUD Mozilla Mozilla基金会,简称Mozilla(缩写MF或MoFo),是为支持和领导开源的Mozilla项目而设立的一个非营利组织. 称作Mozilla公司的子公司,雇佣了一些Mo ...
- JavaScript定时器详解及实例
JS里设定延时: 使用SetInterval和设定延时函数setTimeout 很类似.setTimeout 运用在延迟一段时间,再进行某项操作. setTimeout("function& ...
- Java汉字排序(2)按拼音排序
对于包含汉字的字符串来说,排序的方式主要有两种:一种是拼音,一种是笔画. 本文就讲述如何实现按拼音排序的比较器(Comparator). 作者:Jeff 发表于:2007年12月21日 11:27 最 ...
- JSON格式转换成XML格式
第一种方法: 需要使用命名空间System.Runtime.Serialization.Json 下面有JsonReaderWriterFactory XmlDictionaryReader read ...
- the field is sometimes used inside synchronized block and sometimes used without synchronization
http://stackoverflow.com/questions/28715625/is-it-safe-to-use-field-inside-and-outside-synchronized- ...
- Mac查看端口占用情况
Mac下使用lsof(list open files)来查看端口占用情况,lsof 是一个列出当前系统打开文件的工具. 使用 lsof 会列举所有占用的端口列表: $ lsof 使用less可以用于分 ...
- POJ3691DNA repair
题解: 构建出trie图,令f[i][j]表示到第i个字符走到j号节点最少需要修改的字符数,然后枚举后继节点转移即可. 代码:没写caseWA了n发... #include<cstdio> ...
- 关于 tomcat 集群中 session 共享的三种方法
前两种均需要使用 memcached 或redis 存储 session ,最后一种使用 terracotta 服务器共享. 建议使用 redis,不仅仅因为它可以将缓存的内容持久化,还因为它支持的单 ...
- Java [leetcode 29]Divide Two Integers
题目描述: Divide two integers without using multiplication, division and mod operator. If it is overflow ...