zoukankan      html  css  js  c++  java
  • 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














  • 相关阅读:
    问题.NET--win7 IIS唯一密钥属性“VALUE”设置为“DEFAULT.ASPX”时,无法添加类型为“add”的重复集合
    java传统web项目添加maven管理jar包,log4j无法正常输出日志
    TortoiseSVN设置Beyond Compare为版本比较、差异合并工具
    Win10以管理员身份启动cmd.exe
    SprinMVC中文件上传只在内存保留一份拷贝
    maven项目运行报错invalid LOC header (bad signature)
    c#编写windows服务在开机是OnStart启动超时
    centos安装mysql
    CENTOS7配置静态IP
    @__CheckForDebuggerJustMyCode@4
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/7294361.html
Copyright © 2011-2022 走看看