zoukankan      html  css  js  c++  java
  • ios-汤姆猫

    //
    //  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
  • 相关阅读:
    python基础——列表生成式
    python基础——迭代
    python基础——切片
    python基础——递归函数
    python基础——函数的参数
    python基础——使用dict和set
    python基础——使用list和tuple
    python基础——字符串和编码
    堆——神奇的优先队列(下)
    堆——神奇的优先队列(上)
  • 原文地址:https://www.cnblogs.com/zhuyaguang/p/4689612.html
Copyright © 2011-2022 走看看