使用UISegementControl实现简易Tomcat程序
//
// 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程序的更多相关文章
- JavaScript简易缩放程序
一.前言: 上一篇随笔中已经把拖动程序完成了,这篇主要把缩放程序完成,后面合并后可以做成一个图片裁剪的功能 简易缩放程序DEMO:http://jsfiddle.net/UN99R/ 限制缩放程序DE ...
- J2msi 自己制作的把exe打成安装包简易GUI程序(第二版 带DLL注册)
J2msi 自己制作的把exe打成安装包简易GUI程序(第二版 带DLL注册) 之前那一版本(http://www.cnblogs.com/rojas/p/4794684.html)没考虑 DLL 注 ...
- jmeter测试本地myeclips调试状态下的tomcat程序死锁
在myeclipse调试状态下的tomcat程序,用jmeter测试,居然发生死锁,调试两天无果,直接运行tomcat而不通过myeclipse,无死锁,真是又好气又好笑..
- centos7新增用户并授权root权限、非root用户启动tomcat程序
一.centos7新增用户并授权root权限 cat /etc/redhat-release查看centos版本号 1.禁用root账户登录 vim /etc/ssh/sshd_config 找到这一 ...
- C语言之简易了解程序环境
C语言之简易了解程序环境 大纲: 程序的翻译环境 预编译 编译 汇编 链接 程序的运行环境 在ANSI C的任何一种实现中,存在两个不同的环境. 第1种是翻译环境,在这个环境中源代码被转换为可执行的机 ...
- Python编写简易木马程序(转载乌云)
Python编写简易木马程序 light · 2015/01/26 10:07 0x00 准备 文章内容仅供学习研究.切勿用于非法用途! 这次我们使用Python编写一个具有键盘记录.截屏以及通信功能 ...
- WebSocket基于javaweb+tomcat的简易demo程序
由于项目需要,前端向后台发起请求后,后台需要分成多个步骤进行相关操作,而且不能确定各步骤完成所需要的时间 倘若使用ajax重复访问后台以获取实时数据,显然不合适,无论是对客户端,还是服务端的资源很是浪 ...
- 使用UISegementControl实现简易汤姆猫程序
// // TomViewController.m #import "TomViewController.h" #import <AVFoundation/AVFoundat ...
- 曹工说Tomcat2:自己撸一个简易Tomcat Digester
一.前言 框架代码其实也没那么难,大家不要看着源码就害怕,现在去看 Tomcat 3.0的代码,保证还是看得懂一半,照着撸一遍基本上很多问题都能搞定了.这次我们就模拟 Tomcat 中的 Digest ...
随机推荐
- 最新GitHub新手使用教程(Linux/Ubuntu Git从安装到使用)——详细图解
说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 一.叙述 1.说明:需要在Windows 安装Git的同学,可以查看该篇博客 https://blog.csdn.net/qq_4 ...
- Day2:字典
一.定义 字典是一种“key-value”成对出现的数据类型,中间用冒号把key与value隔,不同的数据用逗号隔开,全部数据用大括号括起来 info = { 'stu1101': "Ten ...
- width:100%和width:inherit
前几天遇到过这么一个问题.我想让子盒子的宽度等于父盒子的宽度.父盒子宽度为一个具体值比如说200px.我将子盒子宽度设为了100%.按道理说应该是可以等于父盒子的宽度的,但结果并没有,而是通栏了.然后 ...
- html的meta标签的charset应该用UTF-8还是utf-8?
之前我也纠结过写html的时候是用<meta charset="UTF-8"/> 或者是 <meta charset="utf-8"/> ...
- 17、网卡驱动程序-DM9000举例
(参考:cs89x0.c可以参考) DM9000 芯片实现网络功能的基础,在接收数据时采用中断方式,即当有数据到来并在 DM9000 内部 CRC 校验通过后会产生一个接收中断: 网卡驱动程序框架: ...
- Java中使用org.json和json-lib解析JSON
文章目录 [隐藏] 一.JavaProject中org.json解析JSON 1.JSON的org.son-api下载 1)JSON网址 2)JSON的java解析org.json-api网址 3) ...
- OpenCV从入门到放弃(五):像素!
一.概念 1.图像本质上面是由数值组成的矩阵.矩阵中的一个元素相应一个像素. 2.对于灰度图像(黑白图像),像素是8位无符号数(CV_8U).0表示黑色,255表示白色.对于彩色图像,是用三原色数据合 ...
- [Redis专辑][1]ubuntu12.04下安装php-redis的方法和步骤
首次公布路径:phpredis的安装 非常久非常久没有写博文了,好多博文都没有整理完成,今天才抽时间整理完这一篇博文,希望能对大家有一定的帮助 首先对redis做个简单的介绍: Redis 是全然开源 ...
- POJ 3628 Bookshelf 2 (01背包)
Bookshelf 2 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7496 Accepted: 3451 Descr ...
- 在 Java 中如何进行 BASE64 编码和解码
BASE64 编码是一种常用的字符编码,在很多地方都会用到.JDK 中提供了非常方便的 BASE64Encoder 和 BASE64Decoder,用它们可以非常方便的完成基于 BASE64 的编码和 ...