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

iOS学习 - 汤姆猫

时间:2015-08-26 21:58:36      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

//
//  YJViewController.m
//  04-汤姆猫的理解
//
//  Created by JACKY-MAC on 15-5-31.
//  Copyright (c) 2015年 www.train.com. All rights reserved.
//

#import "YJViewController.h"

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

@end

@implementation YJViewController
- (void)tomAnimationWithName:(NSString *) name  andCount:(NSInteger)count
{
    if ([self.tom isAnimating]) return;
        
    
    // 动画图片的数
    NSMutableArray *arrayM = [NSMutableArray array];
    
    // 添加动画播放的图片
    
    for (int i=0; i<count; i++) {
        
          // 图像名称
        NSString *imageName = [NSString stringWithFormat:@"%@_%02d.jpg",name,i];
        
        NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:nil];
        UIImage *image = [UIImage imageWithContentsOfFile:path];
        
        [arrayM addObject:image];
    }
    
       // 设置动画数组
    self.tom.animationImages = arrayM;
    
        // 重复1次
    self.tom.animationRepeatCount = 1;
    
        // 动画时长
    self.tom.animationDuration = self.tom.animationImages.count * 0.075;
    
     // 开始动画
    [self.tom startAnimating];
    
    
    // 动画"结束"之后,清理动画数组
    [self.tom performSelector:@selector(setAnimationImages:) withObject:nil
                   afterDelay:self.tom.animationDuration];
    
}
/*
- (IBAction)tomAction:(UIButton *)sender
{
        // currentTitle 可以取出按钮当前的标题文字
    [self tomAnimationWithName:sender.currentTitle andCount:sender.tag];
}

*/
- (IBAction)knockout
{
    [self tomAnimationWithName:@"knockout" andCount:81];
}


- (IBAction)eat
{
    [self tomAnimationWithName:@"eat" andCount:40];
}


- (IBAction)cymbal
{
    [self tomAnimationWithName:@"cymbal" andCount:12];
}

- (IBAction)drink
{
    [self tomAnimationWithName:@"drink" andCount:80];
}

- (IBAction)fart
{
    [self tomAnimationWithName:@"fart" andCount:27];
}

-(IBAction)pie
{
    [self tomAnimationWithName:@"pie" andCount:23];
}

- (IBAction)scratch
{
    [self tomAnimationWithName:@"scratch" andCount:55];
}


- (IBAction)stomach
{
    [self tomAnimationWithName:@"stomach" andCount:34];
}

- (IBAction)footLeft
{
    [self tomAnimationWithName:@"footLeft" andCount:30];
}

- (IBAction)footRight
{
    [self tomAnimationWithName:@"footRight" andCount:30];
}
@end
技术分享

 

iOS学习 - 汤姆猫

标签:

原文地址:http://www.cnblogs.com/yejian/p/4761581.html

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