• 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;
        }
        
        // button上面的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














  • 相关阅读:
    eclipse
    Java SE Runtime Environment
    开源免费的LittleV GUI
    【转】 ARM Cortex-M 系列 MCU 错误追踪库 CmBacktrace
    【转】博客美化(7)推荐几个优秀的自定义博客
    【转】博客美化(6)为你的博文自动添加目录
    【转】博客美化(5)为博客或系统添加一个强大的评论系统
    【转】博客美化(4)为博客添加一个智能的文章推荐插件
    linux管理进程的链表
    连连看游戏(dfs)【华为上机题目】
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/7294361.html
Copyright © 2020-2023  润新知