- //
- // ViewController.m
- // TOM2
- //
- // Created by Mac on 15/11/3.
- // Copyright (c) 2015年 itcat. All rights reserved.
- //
- #import "ViewController.h"
- @interface ViewController ()
- @property (weak, nonatomic) IBOutlet UIImageView *TOM;
- @end
- @implementation ViewController
- -(void)playWithName:(NSString *)name Count:(NSInteger)count{
- //if (self.TOM.isAnimating) return;
- NSMutableArray *array=[NSMutableArray array];
- for (int i=0; i<count; i++) {
-
-
- NSString *imgName=[NSString stringWithFormat:@"%@_%02d.jpg",name,i];
- //imageNamed由系统释放图片 占用内存大 手动释放用imageWithContentsOfFile
- // UIImage *image=[UIImage imageNamed:imgName];
- NSString *path=[[NSBundle mainBundle]pathForResource:imgName ofType:nil];
- UIImage *image=[UIImage imageWithContentsOfFile:path];
- [array addObject:image];
-
- }
-
-
- self.TOM.animationImages=array;
- self.TOM.animationRepeatCount=1;
- self.TOM.animationDuration=self.TOM.animationImages.count*0.075;
- [self.TOM startAnimating];
- //afterDelay:延迟时间执行
- //[self performSelector:@selector(clear) withObject:nil afterDelay:self.TOM.animationDuration];
- //因为 performSelector:是Nsobject的分类 所以这可以直接用@selector(setAnimationImages:) 不用再定义方法
- //[self.TOM performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.TOM.animationDuration];
-
- }
- -(void)clear{
- self.TOM.animationImages=nil;
- }
- - (IBAction)TomAnimations:(UIButton *)sender {
-
- //sender.currentTitle当前按钮的文字必须是(UIButton *)才能用
- [self playWithName:sender.currentTitle Count:sender.tag];
- NSLog(@"%@",sender.currentTitle);
- NSLog(@"%ld",(long)sender.tag);
- NSLog(@"对象已清除");
- NSLog(@"%s",__func__);
-
- }
- @end
复制代码 |