小学期 3
这是很多地方都加了注释,整篇文章是经过写的一个方法,然后对该方法的反复调用。
这些代码实现的是在界面上实现动画的操作和按钮的操作。
// ViewController.m
// 汤姆猫
//
// Created by lanou on 16/7/12.
// Copyright © 2016年 pingguo. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *tomCatView;(定义了一个全局变量)
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// UIImageView *imageView=[UIImageView new];
// 序列成动画要播放的图片数组
// imageView.animationImages
// 动画时长
// imageView.animationDuration
// 动画重复次数
// imageView.animationRepeatCount
// 开始动画
// [imageView startAnimating];
// 结束动画
// [imageView stopAnimating];
// 是否正在执行动画
// [imageView isAnimating];
}
- (IBAction)eatBirdAction:(UIButton *)sender {
[self setTomCatAnimationWithName:@"eat" withCount:40];
/*
// 创建可变数组images,负责存放要播放的图片数组
NSMutableArray *images=[NSMutableArray array];
for (NSInteger i=0; i<40; i++) {
// 根据i来加载图片,然后添加到可变数组images里面
NSString *imageName=[NSString stringWithFormat:@"eat_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image=[UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.tomCatView.animationImages=images;
// 设置动画时长
self.tomCatView.animationDuration=40*0.075;
// 设置动画重复次数
self.tomCatView.animationRepeatCount=1;
// 开始动画
[self.tomCatView startAnimating]; */
}
-(void)setTomCatAnimationWithName:
(NSString*)name withCount:(NSInteger)count
{
// 判断该动画是否正在执行
if ([self.tomCatView isAnimating]) {
return;
}
// 创建可变数组images,负责存放要播放的图片数组
NSMutableArray *images=[NSMutableArray array];
for (NSInteger i=0; i<count; i++) {
// 根据i来加载图片,然后添加到可变数组images里面
NSString *imageName=[NSString stringWithFormat:@"%@_%02ld.jpg",name,i];
// 根据格式化的图片名加载图片image
UIImage *image=[UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.tomCatView.animationImages=images;
// 设置动画时长
self.tomCatView.animationDuration=count*0.075;
// 设置动画重复次数
self.tomCatView.animationRepeatCount=1;
// 开始动画
[self.tomCatView startAnimating];
}
- (IBAction)drink:(UIButton *)sender {
[self setTomCatAnimationWithName:@"drink" withCount:81];
/* NSMutableArray *images=[NSMutableArray array];
for (NSInteger i=0; i<81; i++) {
NSString *imageName=[NSString stringWithFormat:@"drink_%02ld.jpg",i];
UIImage *image=[UIImage imageNamed:imageName];
[images addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=80*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; */
}
- (IBAction)pie:(UIButton *)sender {
[self setTomCatAnimationWithName:@"pie" withCount:24];
/* NSMutableArray *images=[NSMutableArray array];
for (NSInteger i=0; i<24; i++) {
NSString *imageName=[NSString stringWithFormat:@"pie_%02ld.jpg",i];
UIImage *image=[UIImage imageNamed:imageName];
[images addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=24*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; */
}
- (IBAction)scratch:(UIButton *)sender {
[self setTomCatAnimationWithName:@"scratch" withCount:56];
/* NSMutableArray *images=[NSMutableArray array];
for (NSInteger i=0; i<56; i++) {
NSString *imageName=[NSString stringWithFormat:@"scratch_%02ld.jpg",i];
UIImage *image=[UIImage imageNamed:imageName];
[images addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=56*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; */
}
- (IBAction)fart:(UIButton *)sender {
[self setTomCatAnimationWithName:@"fart" withCount:28];
/* NSMutableArray *images=[NSMutableArray array];
for (NSInteger i=0; i<28; i++) {
NSString *imageName=[NSString stringWithFormat:@"fart_%02ld.jpg",i];
UIImage *image=[UIImage imageNamed:imageName];
[images addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=28*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; */
}
- (IBAction)cymbal:(UIButton *)sender {
[self setTomCatAnimationWithName:@"cymbal" withCount:13];
/* NSMutableArray *images=[NSMutableArray array];
for (NSInteger i=0; i<13; i++) {
NSString *imageName=[NSString stringWithFormat:@"cymbal_%02ld.jpg",i];
UIImage *image=[UIImage imageNamed:imageName];
[images addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=13*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; */
}
- (IBAction)knockout:(UIButton *)sender {
[self setTomCatAnimationWithName:@"knockout" withCount:81];
/* NSMutableArray *images=[NSMutableArray array];
for (NSInteger i=0; i<81; i++) {
NSString *imageName=[NSString stringWithFormat:@"knockout_%02ld.jpg",i];
UIImage *image=[UIImage imageNamed:imageName];
[images addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=81*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; */
}
- (IBAction)angry:(UIButton *)sender {
[self setTomCatAnimationWithName:@"angry" withCount:26];
/* NSMutableArray *images=[NSMutableArray array];
for (NSInteger i=0; i<26; i++) {
NSString *imageName=[NSString stringWithFormat:@"angry_%02ld.jpg",i];
UIImage *image=[UIImage imageNamed:imageName];
[images addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=26*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; */
}
- (IBAction)stomach:(UIButton *)sender {
[self setTomCatAnimationWithName:@"stomach" withCount:34];
/* NSMutableArray *images=[NSMutableArray array];
for (NSInteger i=0; i<34; i++) {
NSString *imageName=[NSString stringWithFormat:@"stomach_%02ld.jpg",i];
UIImage *image=[UIImage imageNamed:imageName];
[images addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=34*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; */
}
- (IBAction)footleft:(UIButton *)sender {
[self setTomCatAnimationWithName:@"footLeft" withCount:30];
/* NSMutableArray *images=[NSMutableArray array];
for (NSInteger i=0; i<30; i++) {
NSString *imageName=[NSString stringWithFormat:@"footLeft_%02ld.jpg",i];
UIImage *image=[UIImage imageNamed:imageName];
[images addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=30*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating];*/
}
- (IBAction)footright:(UIButton *)sender {
[self setTomCatAnimationWithName:@"footRight" withCount:30];
/* NSMutableArray *images=[NSMutableArray array];
for (NSInteger i=0; i<30; i++) {
NSString *imageName=[NSString stringWithFormat:@"footRight_%02ld.jpg",i];
UIImage *image=[UIImage imageNamed:imageName];
[images addObject:image];
}
self.tomCatView.animationImages=images;
self.tomCatView.animationDuration=30*0.075;
self.tomCatView.animationRepeatCount=1;
[self.tomCatView startAnimating]; */
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end