黑马程序员技术交流社区
标题:
TOM猫简单实现
[打印本页]
作者:
任子杰
时间:
2015-11-6 00:39
标题:
TOM猫简单实现
<img src="http://bbs.itheima.com/forum.php?mod=image&aid=92465&size=300x300&key=29895ca50aa3c335&nocache=yes&type=fixnone" border="0" aid="attachimg_92465" alt="">
复制代码
屏幕快照 2015-11-03 下午2.17.40.png
(228.95 KB, 下载次数: 31)
下载附件
2015-11-6 00:39 上传
作者:
任子杰
时间:
2015-11-6 00:48
//
// 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
复制代码
作者:
眼瞳╄渲染繁华
时间:
2015-11-6 21:17
你是就业班的吗?
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2