iOS_5_汤姆猫

最终效果图:

BeyondViewController.h

//
//  BeyondViewController.h
//  05_TomCat
//
//  Created by beyond on 14-7-23.
//  Copyright (c) 2014年 com.beyond. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface BeyondViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *imgView_tom;
- (IBAction)btnClick:(UIButton *)sender;

@end

BeyondViewController.m

//
//  BeyondViewController.m
//  05_TomCat
//
//  Created by beyond on 14-7-23.
//  Copyright (c) 2014年 com.beyond. All rights reserved.
//

#import "BeyondViewController.h"

@interface BeyondViewController ()
{
    NSDictionary *_dict;
}

@end

@implementation BeyondViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // sg_bundle模板代码,1,获得.app主要的包;2,返回主要的包中某个文件的fullPath全路径
    NSBundle *mainBundle = [NSBundle mainBundle];
    NSString *fullPath = [mainBundle pathForResource:@"tom.plist" ofType:nil];
    _dict = [NSDictionary dictionaryWithContentsOfFile:fullPath];

}
- (IBAction)btnClick:(UIButton *)sender {
    // 如果正在动画,则直接返回
    if ([_imgView_tom isAnimating]) {
        return;
    }

    // 按钮上面的text就是字典的key,对应值-1是对应动画的图片张数
    // NSString *text = sender.titleLabel.text;
    NSString *text = [sender titleForState:UIControlStateNormal];
    int *picNum = [_dict[text] intValue];
    NSLog(@"%@----%d",text,picNum);

    // 调用自定义方法 播放动画
    [self playAnimatitonNamed:text picNumber:picNum];

}
-(void)playAnimatitonNamed:(NSString *)name picNumber:(int)picNum
{
    // 实例化可变数组
    NSMutableArray *array = [NSMutableArray array];
    // 向可变数组添加UIImage
    for (int i=0; i<picNum; i++) {
        // 生成image方式1,驻留内存,压力过大,真机会崩掉
        NSString *fullName = [NSString stringWithFormat:@"%@_%02d.jpg",name,i];
        UIImage *img = [UIImage imageNamed:fullName];
        // 生成image方式2,IO读取全路径,用完就释放,不驻留内存
        //NSString *fullPath = [[NSBundle mainBundle] pathForResource:fullName ofType:nil];
        //UIImage *img2 = [[UIImage alloc] initWithContentsOfFile:fullPath];
        // 添加UIImage到数组
        [array addObject:img];
    }
    // 设置UIImageView的动画参数,并提交动画
    _imgView_tom.animationImages = array;
    _imgView_tom.animationDuration = 0.1*picNum;
    _imgView_tom.animationRepeatCount = 1;
    [_imgView_tom startAnimating];
}
@end
时间: 2024-08-25 10:34:18

iOS_5_汤姆猫的相关文章

[iOS基础控件 - 3.4] 汤姆猫

需求: 1.点击按钮播放相应动画 2.点击汤姆猫身体部分(头.脚.尾巴)显示动画 3.当前正在播放动画不可触发其他动画 4.优化缓存.内存管理 A.序列帧动画 #1. png格式的文件可以不带扩展名访问,而且可以放到”Images.scassets”的组中预览,jpg只能放到support file中了,而且访问的时候要写上扩展名 #2. 在ViewController中的属性栏可以设置storyboard模型的大小 #3. 拖入文件夹的时候要选择“Create Groups"才能正确引用,不要

在汤姆猫上运行服务

1.cd /usr/local/tomcat/ 2.在此基础上可以创建几个目录,分别叫/tomcat/webapps,在webapps创建libincla目录,并在此目录下分别创建/WEB-INF和并在WEB-INF之下分别创建/classes和/lib,代表我们要部署一个服务了. mkdir /tomcat/webapps –pv cd webapps mkdir libincla [[email protected] libincla]# tree WEB-INF/ WEB-INF/ ├──

汤姆猫游戏核心代码 ios/objective-c

#import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UIImageView *tomImageView; @end @implementation ViewController //敲汤姆猫的头部.前提:一系列动画已经导入. (IBAction)btnKnockOutonclicked:(UIButton *)sender{ [self tomImate

一个不会说话的汤姆猫游戏源码

实现“会说话的汤姆猫” App 互动效果,除了不能发出声音,动画效果与原App十分类似.基本原理是,根据选择的不同动作,播放对应的图像序列.支持图片缓存. 游戏项目源码下载:http://code.662p.com/view/7150.html 详细说明:http://ios.662p.com/thread-1874-1-2.html

汤姆猫的安装、使用。

先要提供jdk-7u9-linux-x64.rpm(如以上版本) 安装jdk(java需要用到的编译开发工具) [[email protected] ~]# rpm -vih jdk-7u9-linux-x64.rpm Preparing...                ########################################### [100%]    1:jdk                    #################################

iOS开发:纯代码实现汤姆猫小游戏

演示效果如下: 代码如下: 1 // 2 // CKViewController.m 3 // 纯代码实现汤姆猫 4 // 5 // Created by FrankChen on 14-12-10. 6 // Copyright (c) 2014年 diaozhatian. All rights reserved. 7 // 8 9 #import "CKViewController.h" 10 11 @interface CKViewController () 12 { 13 //

IOS 开发笔记-基础 UI(7)汤姆猫(UIImageView 的序列帧动画、图片加载,方法重构、Bundle 图片素材)

使用UIImageView.UIButton实现一个综合小案例---汤姆猫 回忆:UIImageView 来自UIView,UIView 来自UIResponder,UIButton 来自UIControl,UIControl 来自UIView 单独看实现,代码实现其实比较简单,但是创意很难得,美工要求很高! 是一个了不起的游戏! 功能分析 (1)点击对应的按钮后,让汤姆猫展现对应的动画 步骤分析 (1)搭建UI界面,同时也是准备素材 (2)监听按钮点击 (3)根据点击的按钮执行对应的动画 说明

IOS 学习04 汤姆猫开发

IOS开发,一个简单的汤姆猫开发,截图如下: 1.1以前一直觉得这个小游戏不错,很好玩,现在学习IOS才发现其实这个程序真心很简单,其实这个还不是个完整,还没有声音,以后再来完整. 1.2 创建项目,导入图片,在项目images.xcassets中保存PNG图片,这里只保存6个按键图片,图片文件直接拉进就可以,如下图: 1.3 相信大多数人都玩过这个小游戏,其实这就是一个动画,而动画就是由多个图片连在一起播放的,最后看起来就是动画了. 1.4 知道了动画的原理,那就好办了,我们再来导入按键相对应

unity汤姆猫自动检测录音,不说话自动播放

unity汤姆猫自动检测录音,不说话自动播放 脚本 using System.Collections.Generic; using System.Linq; using UnityEngine; [RequireComponent(typeof(AudioSource))] public class MicrophoneInput : MonoBehaviour { //每秒种产生0.4M数据量 private LinkedList<float> recordData = new Linked