• IOS 汤姆猫核心代码


    //
    //  MJViewController.m
    //  03-Tom
    //
    //  Created by apple on 13-11-24.
    //  Copyright (c) 2013年 itcast. All rights reserved.
    //
    
    #import "MJViewController.h"
    
    @interface MJViewController () {
    
        NSDictionary *_dict; // 保存所有图片的个数
    }
    @end
    
    @implementation MJViewController
    
    - (void)viewDidLoad {
    
        [super viewDidLoad];
        
        // 1.获得tom.plist的全路径
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *path = [bundle pathForResource:@"tom" ofType:@"plist"];
        
        // 2.根据文件路径加载字典
        _dict = [NSDictionary dictionaryWithContentsOfFile:path];
    }
    
    - (void)playAnim:(int)count fliename:(NSString *)filename {
    
        // 1.创建可变数组
        NSMutableArray *images = [NSMutableArray array];
        
        // 2.添加图片
        for (int i = 0; i<count; i++) {
    	
            // 图片名
            NSString *name = [NSString stringWithFormat:@"%@_%02d.jpg", filename, i];
            // 全路径
            NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil];
            
            // 加载图片(缓存)
    //        UIImage *img = [UIImage imageNamed:name];
            // 没有缓存
            UIImage *img = [[UIImage alloc] initWithContentsOfFile:path];
            
            [images addObject:img];
        }
        
        // 3.设置动画图片(有顺序)
        _tom.animationImages = images;// 序列帧动画
        
        // 4.只播放一次
        _tom.animationRepeatCount = 1;
        
        // 5.设置动画的持续时间
        _tom.animationDuration = 0.1 * count;
        
        // 5.开始动画
        [_tom startAnimating];
    }
    
    #pragma mark 监听所有的按钮点击
    - (IBAction)btnClick:(UIButton *)sender {
    
        // 1.如果tom正在播放动画,直接返回
        if (_tom.isAnimating) return;
        
        // 2.取出按钮文字
        NSString *title = [sender titleForState:UIControlStateNormal];
        
        // 3.获得图片数量
        int count = [_dict[title] intValue];
        
        // 4.播放动画
        [self playAnim:count fliename:title];
    }
    
    @end
    

      

  • 相关阅读:
    数据库的优化
    Java 10
    sleep()和yield()的区别
    mvc框架实现的流程,值得收藏
    MyEclipse项目出现红色!的原因
    The requested resource is not available的解决方案-转载博文
    web.xml详解(web-app_2_3.dtd)规范顺序
    EditText小写字母自动转换成大写(注:设置之后只能显示大写字母)
    Android GridView属性意义集合(转)
    Theme.AppCompat.Light无法找到问题(转)
  • 原文地址:https://www.cnblogs.com/duke-cui/p/4677913.html
Copyright © 2020-2023  润新知