码迷,mamicode.com
首页 > 其他好文 > 详细

TOM猫

时间:2014-05-22 12:38:44      阅读:369      评论:0      收藏:0      [点我收藏+]

标签:ios   基础控件   ios基础控件   tom   tom猫   

bubuko.com,布布扣

===

#import "CHViewController.h"

@interface CHViewController ()

@end

@implementation CHViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}
- (void) playAnimation:(int)count filename:(NSString *)filename{
    //创建可变数组
    NSMutableArray *imagesArray = [[NSMutableArray alloc] init];
    //添加图片
    /*加载图片缓存问题:
     1.有缓存(无法释放,参数传的是文件名)
     [UIImage imageNamed:@""];//经常使用的可以用这个方法
     2.无缓存(用完就会释放,参数传的是全路径)
     [[UIImage alloc] initWithContentsOfFile:path];//占用内存大的不经常使用的用这个
     */
    for(int i=0;i<count;i++){
        NSString *name = [NSString stringWithFormat:@"%@_%02d.jpg",filename,i];
//        UIImage *image = [UIImage imageNamed:name];//有缓存
        NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil];
        UIImage *img = [[UIImage alloc] initWithContentsOfFile:path];//无缓存
        [imagesArray addObject:img];
    }
    //动画效果
    _tom.animationImages = imagesArray;
    _tom.animationDuration = 0.1 * count;
    _tom.animationRepeatCount = 1;
    [_tom startAnimating];
}
    //找到配置文件tom.plist的路径
- (IBAction)btnClick:(UIButton *)sender {
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *path = [bundle pathForResource:@"tom" ofType:@"plist"];
    //根据文件路径加载字典
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
    //获取按钮中的title值
    NSString * title = [sender titleForState:UIControlStateNormal];
    //获取字典中事件对应的图片count
    int count = [dict[title] intValue];
    NSLog(@"%@-%d",title,count);
    [self playAnimation:count filename:title];
}
@end

bubuko.com,布布扣


TOM猫,布布扣,bubuko.com

TOM猫

标签:ios   基础控件   ios基础控件   tom   tom猫   

原文地址:http://blog.csdn.net/kldxcr/article/details/26170929

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!