#import "ViewController.h"
@interface ViewController ()
//标题标签
@property(nonatomic,strong)UILabel *titlelabel;
//左边按钮
@property(nonatomic,strong)UIButton *leftBtn;
//右边按钮
@property(nonatomic,strong)UIButton *rightBtn;
//显示图片
@property(nonatomic,strong)UIImageView *myImageView;
@property(nonatomic,strong)NSArray *imageNames;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.imageNames=@[@"biaoqingdi",@"bingli",@"chiniupa",@"danteng",@"wangba"];
// 创建并初始化标签文本
self.titlelabel=[[UILabel alloc]initWithFrame:CGRectMake(150, 300, 150, 30)];
// 设置标签文本
self.titlelabel.text=@"biaoqingdi";
// 将标签添加到视图
[self.view addSubview:self.titlelabel];
// 创建并初始化左边按钮
self.leftBtn=[[UIButton alloc]
initWithFrame:CGRectMake(20, 150, 45, 45)];
// 关闭交互
self.leftBtn.userInteractionEnabled=NO;
// 根据名字加载图片
UIImage *leftImage=[UIImage imageNamed:@"left_disable"];
// 给左边按钮设置背景图片
[self.leftBtn setBackgroundImage:leftImage forState:
(UIControlStateNormal)];
// 设置左边按钮显示的图片
[self.view addSubview:self.leftBtn];
// 创建并初始化相框
self.myImageView=[[UIImageView alloc]initWithFrame:CGRectMake(85, 100, 200, 200)];
// 根据名字加载图片
UIImage *image=[UIImage imageNamed:@"biaoqingdi"];
self.myImageView.image=image;
// 设置myImageView显示的图片
[self.view addSubview:self.myImageView];
// 创建并初始化右边按钮
self.rightBtn=[[UIButton alloc]initWithFrame:CGRectMake(305, 150, 45, 45)];
// 根据名字加载图片
UIImage *rightImage=[UIImage imageNamed:@"right_normal"];
// 设置右边按钮的背景图片
[self.rightBtn setBackgroundImage:rightImage forState:(UIControlStateNormal)];
// 设置右边按钮显示的图片
[self.view addSubview:self.rightBtn];
[self.rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
[self.leftBtn addTarget:self action:@selector(leftBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
}
-(void)rightBtnAction
{
// 切换到下一张图片
// 获取当前是第几张图片
NSInteger index=[self.imageNames indexOfObject:self.titlelabel.text];
// 不是为最后一张才切换到最后一张
if(index<4){
if(index==3){
// 改变右边按钮颜色和关闭交互
self.rightBtn.userInteractionEnabled=NO;
UIImage *image=[UIImage imageNamed:@"right_disable"];
[self.rightBtn setBackgroundImage:image forState:(UIControlStateNormal)];
}else{
// 左边按钮和右边按钮都是在一个正常状态
self.leftBtn.userInteractionEnabled=YES;
UIImage *leftNormal=[UIImage imageNamed:@"left_normal"];
UIImage *rightNormal=[UIImage imageNamed:@"right_normal"];
[self.leftBtn setBackgroundImage:leftNormal forState:(UIControlStateNormal)];
[self.rightBtn setBackgroundImage:rightNormal forState:(UIControlStateNormal)];
}
// 通过下标访问下一张图片
NSString *nextTitle=self.imageNames[index+1];
self.titlelabel.text=nextTitle;
// 设置相框显示的下一张图片
self.myImageView.image=[UIImage imageNamed:nextTitle];
}
}
-(void)leftBtnAction
{
NSInteger index=[self.imageNames indexOfObject:self.titlelabel.text];
// 不是第一张的时候才切换到上一张
if(index>0){
if(index==1){
// 左边按钮交互关闭,图片切换
self.leftBtn.userInteractionEnabled=NO;
UIImage *image=[UIImage imageNamed:@"left_disable"];
[self.leftBtn setBackgroundImage:image forState:(+UIControlStateNormal)];
}else{
// 左右两边按钮都是正常状态
self.leftBtn.userInteractionEnabled=YES;
UIImage *leftNormal=[UIImage imageNamed:@"left_normal"];
UIImage *rightNormal=[UIImage imageNamed:@"right_normal"];
[self.leftBtn setBackgroundImage:leftNormal forState:(UIControlStateNormal)];
[self.rightBtn setBackgroundImage:rightNormal forState:(UIControlStateNormal)];
self.rightBtn.userInteractionEnabled=YES;
}
NSString *preTitle=self.imageNames[index-1];
self.titlelabel.text=preTitle;
self.myImageView.image=[UIImage imageNamed:preTitle];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
TOM猫
//
// ViewController.m
// TOM
//
// Created by lanou on 16/7/12.
// Copyright © 2016年 lanou. 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 {
NSMutableArray *images = [NSMutableArray array];
// 创建可变数组images,负责存放要播放的图片数组
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];
}
- (IBAction)drinkaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
// 创建可变数组images,负责存放要播放的图片数组
for (NSInteger i = 0; i < 81; i++) {
// 根据I来加载图片,添加到可变数组IMAGES里面、
// 格式化图片
NSString *imageName = [NSString stringWithFormat:@"drink_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.TomCatView.animationImages = images;
// 设置 动画时长
self.TomCatView.animationDuration = 81*0.075;
// 重复次数
self.TomCatView.animationRepeatCount = 1;
// 开始动画
[self.TomCatView startAnimating];
}
- (IBAction)knockoutaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
// 创建可变数组images,负责存放要播放的图片数组
for (NSInteger i = 0; i < 81; i++) {
// 根据I来加载图片,添加到可变数组IMAGES里面、
// 格式化图片
NSString *imageName = [NSString stringWithFormat:@"knockout_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.TomCatView.animationImages = images;
// 设置 动画时长
self.TomCatView.animationDuration = 81*0.075;
// 重复次数
self.TomCatView.animationRepeatCount = 1;
// 开始动画
[self.TomCatView startAnimating];
}
- (IBAction)Tompieaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
// 创建可变数组images,负责存放要播放的图片数组
for (NSInteger i = 0; i < 24; i++) {
// 根据I来加载图片,添加到可变数组IMAGES里面、
// 格式化图片
NSString *imageName = [NSString stringWithFormat:@"pie_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.TomCatView.animationImages = images;
// 设置 动画时长
self.TomCatView.animationDuration = 24*0.075;
// 重复次数
self.TomCatView.animationRepeatCount = 1;
// 开始动画
[self.TomCatView startAnimating];
}
- (IBAction)qiaoluoaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
// 创建可变数组images,负责存放要播放的图片数组
for (NSInteger i = 0; i < 13; i++) {
// 根据I来加载图片,添加到可变数组IMAGES里面、
// 格式化图片
NSString *imageName = [NSString stringWithFormat:@"Cymbal_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.TomCatView.animationImages = images;
// 设置 动画时长
self.TomCatView.animationDuration = 13*0.075;
// 重复次数
self.TomCatView.animationRepeatCount = 1;
// 开始动画
[self.TomCatView startAnimating];
}
- (IBAction)Tomfartaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
// 创建可变数组images,负责存放要播放的图片数组
for (NSInteger i = 0; i < 28; i++) {
// 根据I来加载图片,添加到可变数组IMAGES里面、
// 格式化图片
NSString *imageName = [NSString stringWithFormat:@"fart_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.TomCatView.animationImages = images;
// 设置 动画时长
self.TomCatView.animationDuration = 28*0.075;
// 重复次数
self.TomCatView.animationRepeatCount = 1;
// 开始动画
[self.TomCatView startAnimating];
}
- (IBAction)scratchaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
// 创建可变数组images,负责存放要播放的图片数组
for (NSInteger i = 0; i < 56; i++) {
// 根据I来加载图片,添加到可变数组IMAGES里面、
// 格式化图片
NSString *imageName = [NSString stringWithFormat:@"scratch_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.TomCatView.animationImages = images;
// 设置 动画时长
self.TomCatView.animationDuration = 56*0.075;
// 重复次数
self.TomCatView.animationRepeatCount = 1;
// 开始动画
[self.TomCatView startAnimating];
}
- (IBAction)angryaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
// 创建可变数组images,负责存放要播放的图片数组
for (NSInteger i = 0; i < 26; i++) {
// 根据I来加载图片,添加到可变数组IMAGES里面、
// 格式化图片
NSString *imageName = [NSString stringWithFormat:@"angry_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.TomCatView.animationImages = images;
// 设置 动画时长
self.TomCatView.animationDuration = 26*0.075;
// 重复次数
self.TomCatView.animationRepeatCount = 1;
// 开始动画
[self.TomCatView startAnimating];
}
- (IBAction)sromachaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
// 创建可变数组images,负责存放要播放的图片数组
for (NSInteger i = 0; i < 34; i++) {
// 根据I来加载图片,添加到可变数组IMAGES里面、
// 格式化图片
NSString *imageName = [NSString stringWithFormat:@"stomach_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.TomCatView.animationImages = images;
// 设置 动画时长
self.TomCatView.animationDuration = 34*0.075;
// 重复次数
self.TomCatView.animationRepeatCount = 1;
// 开始动画
[self.TomCatView startAnimating];
}
- (IBAction)rightatcion:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
// 创建可变数组images,负责存放要播放的图片数组
for (NSInteger i = 0; i < 30; i++) {
// 根据I来加载图片,添加到可变数组IMAGES里面、
// 格式化图片
NSString *imageName = [NSString stringWithFormat:@"footright_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.TomCatView.animationImages = images;
// 设置 动画时长
self.TomCatView.animationDuration = 30*0.075;
// 重复次数
self.TomCatView.animationRepeatCount = 1;
// 开始动画
[self.TomCatView startAnimating];
}
- (IBAction)leftaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
// 创建可变数组images,负责存放要播放的图片数组
for (NSInteger i = 0; i < 30; i++) {
// 根据I来加载图片,添加到可变数组IMAGES里面、
// 格式化图片
NSString *imageName = [NSString stringWithFormat:@"footleft_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[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