//
// TomViewController.m #import "TomViewController.h"
#import <AVFoundation/AVFoundation.h> @interface TomViewController () @property (nonatomic, retain) UIImageView * imageView; @property (nonatomic, retain) AVAudioPlayer *player; @end @implementation TomViewController - (void)dealloc
{
self.imageView = nil;
self.player = nil;
[super dealloc];
} - (void)viewDidLoad {
[super viewDidLoad]; // 初始化imageView属性
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"angry_00.jpg"]];
_imageView.frame = [UIScreen mainScreen].bounds;
[self.view addSubview:_imageView];
[_imageView release]; // 准备title数组
NSArray *titles = @[@"吃鸟", @"生气", @"放屁"];
// 使用title数组初始化UISegmentControl
UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:titles];
// 配置属性
// 设置frame,每一个item等分总的宽度
segmentControl.frame = CGRectMake(60, 20, 200, 30);
segmentControl.tintColor = [UIColor yellowColor];// 字体,边框颜色
//segmentControl.selectedSegmentIndex = 0; [self.view addSubview:segmentControl];
[segmentControl release]; // 给segementControl设置关联事件
[segmentControl addTarget:self action:@selector(handleSegmentControl:) forControlEvents:(UIControlEventValueChanged)]; }
#pragma mark - UISegementControl的关联事件实现方法
- (void)handleSegmentControl:(UISegmentedControl *)sender {
// sender.selectedSegementIndex 获取选中的分段下标
switch (sender.selectedSegmentIndex) { case 0:// 吃鸟
[self eat];
break; case 1: // 生气
[self angry];
break; case 2: // 放屁
[self fart];
break; default:
break;
} }
#pragma mark - 吃鸟的方法实现
- (void)eat {
// 先停止播放,再释放上一次使用的播放器对象
[self.player stop];
self.player = nil;
// 如果正在播放动画,点击不响应
if (_imageView.isAnimating) {
return;
}
// 调用获取动画数组的方法 制作动画
_imageView.animationImages = [self getAnimationArrayWithImageName:@"eat" andImageCount:40]; _imageView.animationDuration = 4;
_imageView.animationRepeatCount = 1;// 点击播放一次
[_imageView startAnimating];// 开启动画 //创建播放器对象(包括 准备文件路径, 准备播放器NSURL对象,初始化播放器对象 三步)
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:[[NSBundle mainBundle]pathForResource:@"p_eat.m4a" ofType:nil]] error:nil];
[_player release];
[_player play]; }
#pragma mark - 生气的方法实现
- (void)angry { [self.player stop];
self.player = nil; if (_imageView.isAnimating) {
return;
} _imageView.animationImages = [self getAnimationArrayWithImageName:@"angry" andImageCount:26];
_imageView.animationRepeatCount = 1;
_imageView.animationDuration = 2;
[_imageView startAnimating]; self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:[[NSBundle mainBundle]pathForResource:@"angry.m4a" ofType:nil]] error:nil];
[_player release];
[_player play]; } #pragma mark - 放屁的方法实现
- (void)fart { [self.player stop];
self.player = nil; if (_imageView.isAnimating) {
return;
} _imageView.animationImages = [self getAnimationArrayWithImageName:@"fart" andImageCount:28];
_imageView.animationDuration = 4;
_imageView.animationRepeatCount = 1;
[_imageView startAnimating]; self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"fart003_11025.m4a" ofType:nil]] error:nil];
[_player release];
[_player play]; } // 提供一个返回动画数组的方法 两个参数(图片名 和 对应图片的数量)
- (NSMutableArray *)getAnimationArrayWithImageName:(NSString *)name andImageCount:(int)count {
// 准备图片数组
NSMutableArray *imageArray = [NSMutableArray arrayWithCapacity:count];
// 循环取出一组动画中的全部图片
for (int i = 0; i < count; i++) { NSString *imageName = [NSString stringWithFormat:@"%@_%02d.jpg", name, i];// %02d:占位为2, 10以内的十位用0 UIImage *image = [UIImage imageNamed:imageName];// 创建UIImage对象 [imageArray addObject:image]; // 照片添加到数组中 } return imageArray; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

使用UISegementControl实现简易Tomcat程序的更多相关文章

  1. JavaScript简易缩放程序

    一.前言: 上一篇随笔中已经把拖动程序完成了,这篇主要把缩放程序完成,后面合并后可以做成一个图片裁剪的功能 简易缩放程序DEMO:http://jsfiddle.net/UN99R/ 限制缩放程序DE ...

  2. J2msi 自己制作的把exe打成安装包简易GUI程序(第二版 带DLL注册)

    J2msi 自己制作的把exe打成安装包简易GUI程序(第二版 带DLL注册) 之前那一版本(http://www.cnblogs.com/rojas/p/4794684.html)没考虑 DLL 注 ...

  3. jmeter测试本地myeclips调试状态下的tomcat程序死锁

    在myeclipse调试状态下的tomcat程序,用jmeter测试,居然发生死锁,调试两天无果,直接运行tomcat而不通过myeclipse,无死锁,真是又好气又好笑..

  4. centos7新增用户并授权root权限、非root用户启动tomcat程序

    一.centos7新增用户并授权root权限 cat /etc/redhat-release查看centos版本号 1.禁用root账户登录 vim /etc/ssh/sshd_config 找到这一 ...

  5. C语言之简易了解程序环境

    C语言之简易了解程序环境 大纲: 程序的翻译环境 预编译 编译 汇编 链接 程序的运行环境 在ANSI C的任何一种实现中,存在两个不同的环境. 第1种是翻译环境,在这个环境中源代码被转换为可执行的机 ...

  6. Python编写简易木马程序(转载乌云)

    Python编写简易木马程序 light · 2015/01/26 10:07 0x00 准备 文章内容仅供学习研究.切勿用于非法用途! 这次我们使用Python编写一个具有键盘记录.截屏以及通信功能 ...

  7. WebSocket基于javaweb+tomcat的简易demo程序

    由于项目需要,前端向后台发起请求后,后台需要分成多个步骤进行相关操作,而且不能确定各步骤完成所需要的时间 倘若使用ajax重复访问后台以获取实时数据,显然不合适,无论是对客户端,还是服务端的资源很是浪 ...

  8. 使用UISegementControl实现简易汤姆猫程序

    // // TomViewController.m #import "TomViewController.h" #import <AVFoundation/AVFoundat ...

  9. 曹工说Tomcat2:自己撸一个简易Tomcat Digester

    一.前言 框架代码其实也没那么难,大家不要看着源码就害怕,现在去看 Tomcat 3.0的代码,保证还是看得懂一半,照着撸一遍基本上很多问题都能搞定了.这次我们就模拟 Tomcat 中的 Digest ...

随机推荐

  1. 设计模式--单例模式之Lock

    1.为什么用Lock及关键知识 当我们使用线程的时候,效率最高的方式当然是异步,即个个线程同时运行,其间互不依赖和等待.当不同的线程都需要访问某个资源的时候,就需要同步机制了,也就是说当对同一个资源进 ...

  2. POJ 2752 Seek the Name, Seek the Fame (KMP)

    传送门 http://poj.org/problem?id=2752 题目大意:求既是前缀又是后缀的前缀的可能的长度.. 同样是KMP,和 HDU 2594 Simpsons' Hidden Tale ...

  3. 5、regulator系统的概念及测试

    概念:Regulator : 电源芯片, 比如电压转换芯片Consumer : 消费者,使用电源的部件, Regulator是给Consumer供电的machine : 单板,上面焊接有Regulat ...

  4. thinkphp3.1课程 1-1 为什么thinkphp在开发好后需要关掉开发模式

    thinkphp3.1课程 1-1 为什么thinkphp在开发好后需要关掉开发模式 一.总结 一句话总结:因为调试模式中会记录你所有的调试信息,比如a调用b,b调用c,c调用d,比如你从哪个数据库取 ...

  5. Linux 系统 杀Oracle 进程

    Linux 系统 杀Oracle 进程 杀掉进程用此方法比较好,能保证杀得干净,而不是用SQL  alter system kill kill -9 `ps -ef|grep "oracle ...

  6. Multi-core compute cache coherency with a release consistency memory ordering model

    A method includes storing, with a first programmable processor, shared variable data to cache lines ...

  7. [React] Create & Deploy a Universal React App using Zeit Next

    In this lesson, we'll use next to create a universal React application with no configuration. We'll ...

  8. 《JavaScript &amp; jQuery交互式Web前端开发》之JavaScript基础指令

           在本节中.你将開始学习阅读和编写JavaScript代码,还将学习怎样编写Web浏览器可以遵照运行的指令.在開始学习后面章节中的更复杂的概念之前.我们先学习语言的一些核心部分,然后看看怎 ...

  9. php 获取根目录

    在网站根目录的index.php文件里 define('BASE_PATH',str_replace('\\','/',realpath(dirname(__FILE__).'/'))."/ ...

  10. MS SQL Server的STRING_SPLIT和STRING_AGG函数

    在较新版本的SQL中,出现有2个函数,STRING_SPLIT和STRING_AGG,前者是把带有分隔的字符串转换为表,而后者却是把表某一表转换为以某种字符分隔的字符串. 如下面: DECLARE @ ...