码迷,mamicode.com
首页 > 移动开发 > 详细

ios-汤姆猫

时间:2015-07-30 16:48:49      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

//
//  ViewController.m
//  汤姆猫
//
//  Created by YaguangZhu on 15/7/30.
//  Copyright (c) 2015年 YaguangZhu. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
- (IBAction)drink;
@property (weak, nonatomic) IBOutlet UIImageView *imgCat;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)drink {
    
    //如果当前在执行动画 这按钮实效
    if (self.imgCat.isAnimating) {
        return;
    }
    NSMutableArray *arrayM = [NSMutableArray array];
    
    for (int i = 1; i<=11; i++) {
        NSString *imgName = [NSString stringWithFormat:@"%02d.png",i];
        //太耗内存了,换一种方法
        UIImage *imageCat = [UIImage imageNamed:imgName];
       // NSString *path = [[NSBundle mainBundle] pathForResource:imgName ofType:nil];
        //UIImage *imageCat = [UIImage imageWithContentsOfFile:path];
        [arrayM addObject:imageCat];
        
       
    }
    self.imgCat.animationImages =arrayM;
    
    self.imgCat.animationDuration = self.imgCat.animationImages.count*1;
    [self.imgCat startAnimating];
    
    //为了节省内存 让动画执行完 延迟执行
    [self.imgCat performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.imgCat.animationImages.count*1];
    
}
@end

 

ios-汤姆猫

标签:

原文地址:http://www.cnblogs.com/zhuyaguang/p/4689612.html

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