iOS 自制汤姆猫
来源:互联网 发布:sql完整复杂查询例题 编辑:程序博客网 时间:2024/04/28 09:00
效果图如下:
#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<count; i++) { NSString *imageName = [NSString stringWithFormat:@"%@_%02d.jpg",name,i]; NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:nil]; UIImage *image = [UIImage imageWithContentsOfFile:path]; [images addObject:image]; } imageView.animationImages = images; imageView.animationRepeatCount = 1; imageView.animationDuration = images.count*0.05; [imageView startAnimating]; CGFloat delay = imageView.animationDuration +0.1; [imageView performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:delay]; }- (void)leftAction:(UIButton *)sender{ switch (sender.tag) { case 1: [self loadAnimationWithCount:55 name:@"scratch"]; break; case 2: [self loadAnimationWithCount:23 name:@"pie"]; break; case 3: [self loadAnimationWithCount:80 name:@"drink"]; break; case 100: [self loadAnimationWithCount:33 name:@"stomach"]; break; case 101: [self loadAnimationWithCount:29 name:@"foot_left"]; break; case 102: [self loadAnimationWithCount:29 name:@"foot_right"]; break; default: break; }}- (void)rightAction:(UIButton *)sender{ switch (sender.tag) { case 10: [self loadAnimationWithCount:27 name:@"fart"]; break; case 11: [self loadAnimationWithCount:39 name:@"eat"]; break; case 12: [self loadAnimationWithCount:12 name:@"cymbal"]; break; default: break; }}
这个汤姆猫主要是利用button来控制图片而已,不过我们的图片是所有的图片和在一起的,看起来就像是一连串的动作。本人知识有限,如有其它建议或者意见,必会虚心 改进。
0 0
- iOS 自制汤姆猫
- IOS汤姆猫小练习
- ios-day02-05(汤姆猫)
- 汤姆猫iOS案例总结
- iOS-汤姆猫项目总结
- IOS 汤姆猫核心代码
- [iOS] 经典应用-汤姆猫
- IOS--简单的汤姆猫代码
- ios-UI-汤姆猫德游戏实现
- iOS开发-------汤姆猫实例(UIImageView)
- iOS学习之路-简单汤姆猫
- 汤姆猫
- 汤姆猫
- 【成长记录】iOS小程序-不会说话的汤姆猫
- swift开发ios笔记2--汤姆猫动画(帧动画)
- IOS基础UI之(四)汤姆猫的实现
- iOS笔记UI--汤姆猫小项目(UIbutton使用)
- iOS_5_汤姆猫
- 自定义dialog样式
- Android 如何找出项目中无用多余的资源
- RESTful API 设计最佳实践
- Linux块设备驱动之NAND FLASH
- 机器学习基石 作业1 实现PLA和Pocket算法
- iOS 自制汤姆猫
- hdu5117 Fluorescent DP,期望
- 神盾淘宝后台修改器高级版最新版介绍
- 百度地图---SDKInitializer.initialize(Unknown Source)
- 原码、反码、补码的由来和计算
- JS实现表格使用上下左右键聚集
- Common:序列化
- javascript计时器
- Notepad++