iOS 自制汤姆猫



效果图如下:

iOS 自制汤姆猫_第1张图片


#import "twoViewController.h"

@interface twoViewController ()
{
    UIImageView *imageView;
    
    UIImageView *animationView_stomach;
    NSMutableArray *imageList_stomach;
    
    UIImageView *animationView_footleft;
    NSMutableArray *imageList_footleft;
    
    UIImageView *animationView_footright;
    NSMutableArray *imageList_footright;
}
@end

@implementation twoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    self.view.backgroundColor = [UIColor grayColor];
    
    imageView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    imageView.image = [UIImage imageNamed:@"fart_00.jpg"];
    [self.view addSubview:imageView];
    
    // 胃部
    UIButton *b_stomach = [UIButton buttonWithType:UIButtonTypeCustom];
    b_stomach.frame = CGRectMake(150, 450, 80, 100);
    [b_stomach addTarget:self action:@selector(leftAction:) forControlEvents:UIControlEventTouchUpInside];
    b_stomach.tag = 100;
     [self.view addSubview:b_stomach];
    
    // 左脚
    UIButton *b_footleft = [UIButton buttonWithType:UIButtonTypeCustom];
    b_footleft.frame = CGRectMake(190, 600, 50, 50);
    [b_footleft addTarget:self action:@selector(leftAction:) forControlEvents:UIControlEventTouchUpInside];
    b_footleft.tag = 101;
    [self.view addSubview:b_footleft];
    
    // 右脚
    UIButton *b_footright = [UIButton buttonWithType:UIButtonTypeCustom];
    b_footright.frame = CGRectMake(130, 600, 50, 50);
    [b_footright addTarget:self action:@selector(leftAction:) forControlEvents:UIControlEventTouchUpInside];
    b_footright.tag = 102;
    [self.view addSubview:b_footright];
    
    
    NSArray *arr = @[@"scratch",@"pie",@"drink",@"fart",@"eat",@"cymbal"];
    // 左边三个按钮动作
    for (int i = 0; i<3; i++) {
        UIButton *bleft = [UIButton buttonWithType:UIButtonTypeCustom];
        bleft.frame = CGRectMake(0, 300+(50+10)*i, 50, 50);
        bleft.tag = i+1;
        [bleft setBackgroundImage:[UIImage imageNamed:arr[i]] forState:UIControlStateNormal];
        [self.view addSubview:bleft];
        [bleft addTarget:self action:@selector(leftAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    // 右边三个按钮动作
    for (int j = 0; j<3; j++) {
        UIButton *bright = [UIButton buttonWithType:UIButtonTypeCustom];
        bright.frame = CGRectMake(375-50, 300+(50+10)*j, 50, 50);
        bright.tag = j+10;
        [bright setBackgroundImage:[UIImage imageNamed:arr[3+j]] forState:UIControlStateNormal];
        [self.view addSubview:bright];
        [bright addTarget:self action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
    }
}

- (void)loadAnimationWithCount:(int)count name:(NSString *)name
{
    if ([imageView isAnimating]) {
        return;
    }
//    把图片里面的数据 加载到内存 然后再从内存里面 获得图片数据
    NSMutableArray *images = [NSMutableArray array];
//    如果读取高质量的图片 可以采取以下方式
    for (int i =0; i

这个汤姆猫主要是利用button来控制图片而已,不过我们的图片是所有的图片和在一起的,看起来就像是一连串的动作。本人知识有限,如有其它建议或者意见,必会虚心 改进。



你可能感兴趣的:(小项目设计)