首页 > 其他 > 详细

Tom猫

时间:2015-03-23 13:14:51      阅读:252      评论:0      收藏:0      [点我收藏+]

技术分享

 

 

 

//

//  ViewController.m

//  TomCat2

//

//

 

#import "ViewController.h"

 

@interface ViewController ()

 

@property (weak, nonatomic) IBOutlet UIImageView *tom;

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad

{

    [super viewDidLoad];

    

    NSString *bundlePath = [[[NSBundle mainBundle] bundlePath]stringByAppendingPathComponent:@"ainimals"];

    NSString *filePath = [NSString stringWithFormat:@"%@/Drink/drink_00.jpg",bundlePath];

    

    self.tom.image = [UIImage imageWithContentsOfFile:filePath];

}

 

- (void)runAnimationWithName:(NSString *)name

{

    if (self.tom.isAnimating) return;

    

    // 1.设置Tom的动画数组

    NSMutableArray *arrayM = [NSMutableArray array];

    

    NSString *bundlePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"ainimals"];

    NSString *animPath = [bundlePath stringByAppendingPathComponent:name];

    

    // NSFileManager是专门用来做磁盘文件管理的

    // 取出指定目录中的所有文件

    NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:animPath error:NULL];

    NSLog(@"%@",files);

    

    for (NSString *fileName in files) {

        NSString *filePath = [NSString stringWithFormat:@"%@/%@",animPath,fileName];

        

        UIImage *image = [UIImage imageWithContentsOfFile:filePath];

        

        [arrayM addObject:image];

    }

    

    self.tom.animationImages = arrayM;

    self.tom.animationDuration = arrayM.count * 0.075;

    self.tom.animationRepeatCount = 1;

    

    // 2.开始播放

    [self.tom startAnimating];

    NSLog(@"%f",self.tom.animationDuration);

    

    // 3.清空动画数组

    [self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration];

    

}

 

-(IBAction)tomAction:(UIButton *)button

{

    [self runAnimationWithName:button.currentTitle];

}

 

@end

 

Tom猫

原文:http://www.cnblogs.com/Holy-Mac/p/4359338.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!