#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"];
// ? ?創(chuàng)建并初始化標簽文本
? self.titlelabel=[[UILabel alloc]initWithFrame:CGRectMake(150, 300, 150, 30)];
// ? ?設置標簽文本
? self.titlelabel.text=@"biaoqingdi";
// ? ?將標簽添加到視圖
? [self.view addSubview:self.titlelabel];
// ? ?創(chuàng)建并初始化左邊按鈕
? self.leftBtn=[[UIButton alloc]
? ? ? ? ? ? ? ? initWithFrame:CGRectMake(20, 150, 45, 45)];
// ? ?關閉交互
? self.leftBtn.userInteractionEnabled=NO;
// ? ?根據(jù)名字加載圖片
? UIImage *leftImage=[UIImage imageNamed:@"left_disable"];
// ? ?給左邊按鈕設置背景圖片
? [self.leftBtn setBackgroundImage:leftImage forState:
? ?(UIControlStateNormal)];
// ? ?設置左邊按鈕顯示的圖片
? [self.view addSubview:self.leftBtn];
// ? ?創(chuàng)建并初始化相框
? self.myImageView=[[UIImageView alloc]initWithFrame:CGRectMake(85, 100, 200, 200)];
// ? ?根據(jù)名字加載圖片
? UIImage *image=[UIImage imageNamed:@"biaoqingdi"];
? self.myImageView.image=image;
// ? ?設置myImageView顯示的圖片
? [self.view addSubview:self.myImageView];
// ? ?創(chuàng)建并初始化右邊按鈕
? self.rightBtn=[[UIButton alloc]initWithFrame:CGRectMake(305, 150, 45, 45)];
// ? ?根據(jù)名字加載圖片
? 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{
// ? ? ? ? ? ?左邊按鈕和右邊按鈕都是在一個正常狀態(tài)
? ? ? ? ? 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{
// ? ? ? ? ? ?左右兩邊按鈕都是正常狀態(tài)
? ? ? ? ? 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];
//序列幀動畫要播放的圖片數(shù)組
// ? ? ? imageView.animationImages
//動畫時長
? // ? ?imageView.animationDuration
//動畫重復次數(shù)
// ? ?imageView.animationRepeatCount
// ? ?開始動畫
// ? ?[imageView startAnimating];
// ? ?結束動畫
// ? ?[imageView stopAnimating];
// ? ?是否正在執(zhí)行動畫
// ? ?[imageView isAnimating]'
}
- (IBAction)eatBirdaction:(UIButton *)sender {
? NSMutableArray *images = [NSMutableArray array];
// ? ?創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組
? for (NSInteger i = 0; i < 40; i++) {
// ? ? ? ?根據(jù)I來加載圖片猖凛,添加到可變數(shù)組IMAGES里面赂蠢、
// ? ? ? ?格式化圖片
? ? ? NSString *imageName = [NSString stringWithFormat:@"eat_%02ld.jpg",i];
// ? ? ? ?根據(jù)格式化的圖片名加載圖片image
? ? ? UIImage *image = [UIImage imageNamed:imageName];
// ? ? ? ?將圖片image添加到數(shù)組images中
? ? ? [images addObject:image];
? }
// ? 設置動畫圖片數(shù)組
? self.TomCatView.animationImages = images;
// ?設置 動畫時長
? self.TomCatView.animationDuration = 40*0.075;
// ? 重復次數(shù)
? self.TomCatView.animationRepeatCount = 1;
// ? ?開始動畫
? [self.TomCatView startAnimating];
}
- (IBAction)drinkaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
? // ? ?創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組
? for (NSInteger i = 0; i < 81; i++) {
? ? ? // ? ? ? ?根據(jù)I來加載圖片辨泳,添加到可變數(shù)組IMAGES里面虱岂、
? ? ? // ? ? ? ?格式化圖片
? ? ? NSString *imageName = [NSString stringWithFormat:@"drink_%02ld.jpg",i];
? ? ? // ? ? ? ?根據(jù)格式化的圖片名加載圖片image
? ? ? UIImage *image = [UIImage imageNamed:imageName];
? ? ? // ? ? ? ?將圖片image添加到數(shù)組images中
? ? ? [images addObject:image];
? }
? // ? 設置動畫圖片數(shù)組
? self.TomCatView.animationImages = images;
? // ?設置 動畫時長
? self.TomCatView.animationDuration = 81*0.075;
? // ? 重復次數(shù)
? self.TomCatView.animationRepeatCount = 1;
? // ? ?開始動畫
? [self.TomCatView startAnimating];
}
- (IBAction)knockoutaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
? // ? ?創(chuàng)建可變數(shù)組images玖院,負責存放要播放的圖片數(shù)組
? for (NSInteger i = 0; i < 81; i++) {
? ? ? // ? ? ? ?根據(jù)I來加載圖片,添加到可變數(shù)組IMAGES里面第岖、
? ? ? // ? ? ? ?格式化圖片
? ? ? NSString *imageName = [NSString stringWithFormat:@"knockout_%02ld.jpg",i];
? ? ? // ? ? ? ?根據(jù)格式化的圖片名加載圖片image
? ? ? UIImage *image = [UIImage imageNamed:imageName];
? ? ? // ? ? ? ?將圖片image添加到數(shù)組images中
? ? ? [images addObject:image];
? }
? // ? 設置動畫圖片數(shù)組
? self.TomCatView.animationImages = images;
? // ?設置 動畫時長
? self.TomCatView.animationDuration = 81*0.075;
? // ? 重復次數(shù)
? self.TomCatView.animationRepeatCount = 1;
? // ? ?開始動畫
? [self.TomCatView startAnimating];
}
- (IBAction)Tompieaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
? // ? ?創(chuàng)建可變數(shù)組images难菌,負責存放要播放的圖片數(shù)組
? for (NSInteger i = 0; i < 24; i++) {
? ? ? // ? ? ? ?根據(jù)I來加載圖片,添加到可變數(shù)組IMAGES里面蔑滓、
? ? ? // ? ? ? ?格式化圖片
? ? ? NSString *imageName = [NSString stringWithFormat:@"pie_%02ld.jpg",i];
? ? ? // ? ? ? ?根據(jù)格式化的圖片名加載圖片image
? ? ? UIImage *image = [UIImage imageNamed:imageName];
? ? ? // ? ? ? ?將圖片image添加到數(shù)組images中
? ? ? [images addObject:image];
? }
? // ? 設置動畫圖片數(shù)組
? self.TomCatView.animationImages = images;
? // ?設置 動畫時長
? self.TomCatView.animationDuration = 24*0.075;
? // ? 重復次數(shù)
? self.TomCatView.animationRepeatCount = 1;
? // ? ?開始動畫
? [self.TomCatView startAnimating];
}
- (IBAction)qiaoluoaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
? // ? ?創(chuàng)建可變數(shù)組images郊酒,負責存放要播放的圖片數(shù)組
? for (NSInteger i = 0; i < 13; i++) {
? ? ? // ? ? ? ?根據(jù)I來加載圖片,添加到可變數(shù)組IMAGES里面键袱、
? ? ? // ? ? ? ?格式化圖片
? ? ? NSString *imageName = [NSString stringWithFormat:@"Cymbal_%02ld.jpg",i];
? ? ? // ? ? ? ?根據(jù)格式化的圖片名加載圖片image
? ? ? UIImage *image = [UIImage imageNamed:imageName];
? ? ? // ? ? ? ?將圖片image添加到數(shù)組images中
? ? ? [images addObject:image];
? }
? // ? 設置動畫圖片數(shù)組
? self.TomCatView.animationImages = images;
? // ?設置 動畫時長
? self.TomCatView.animationDuration = 13*0.075;
? // ? 重復次數(shù)
? self.TomCatView.animationRepeatCount = 1;
? // ? ?開始動畫
? [self.TomCatView startAnimating];
}
- (IBAction)Tomfartaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
? // ? ?創(chuàng)建可變數(shù)組images猎塞,負責存放要播放的圖片數(shù)組
? for (NSInteger i = 0; i < 28; i++) {
? ? ? // ? ? ? ?根據(jù)I來加載圖片,添加到可變數(shù)組IMAGES里面杠纵、
? ? ? // ? ? ? ?格式化圖片
? ? ? NSString *imageName = [NSString stringWithFormat:@"fart_%02ld.jpg",i];
? ? ? // ? ? ? ?根據(jù)格式化的圖片名加載圖片image
? ? ? UIImage *image = [UIImage imageNamed:imageName];
? ? ? // ? ? ? ?將圖片image添加到數(shù)組images中
? ? ? [images addObject:image];
? }
? // ? 設置動畫圖片數(shù)組
? self.TomCatView.animationImages = images;
? // ?設置 動畫時長
? self.TomCatView.animationDuration = 28*0.075;
? // ? 重復次數(shù)
? self.TomCatView.animationRepeatCount = 1;
? // ? ?開始動畫
? [self.TomCatView startAnimating];
}
- (IBAction)scratchaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
? // ? ?創(chuàng)建可變數(shù)組images荠耽,負責存放要播放的圖片數(shù)組
? for (NSInteger i = 0; i < 56; i++) {
? ? ? // ? ? ? ?根據(jù)I來加載圖片,添加到可變數(shù)組IMAGES里面比藻、
? ? ? // ? ? ? ?格式化圖片
? ? ? NSString *imageName = [NSString stringWithFormat:@"scratch_%02ld.jpg",i];
? ? ? // ? ? ? ?根據(jù)格式化的圖片名加載圖片image
? ? ? UIImage *image = [UIImage imageNamed:imageName];
? ? ? // ? ? ? ?將圖片image添加到數(shù)組images中
? ? ? [images addObject:image];
? }
? // ? 設置動畫圖片數(shù)組
? self.TomCatView.animationImages = images;
? // ?設置 動畫時長
? self.TomCatView.animationDuration = 56*0.075;
? // ? 重復次數(shù)
? self.TomCatView.animationRepeatCount = 1;
? // ? ?開始動畫
? [self.TomCatView startAnimating];
}
- (IBAction)angryaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
? // ? ?創(chuàng)建可變數(shù)組images铝量,負責存放要播放的圖片數(shù)組
? for (NSInteger i = 0; i < 26; i++) {
? ? ? // ? ? ? ?根據(jù)I來加載圖片,添加到可變數(shù)組IMAGES里面银亲、
? ? ? // ? ? ? ?格式化圖片
? ? ? NSString *imageName = [NSString stringWithFormat:@"angry_%02ld.jpg",i];
? ? ? // ? ? ? ?根據(jù)格式化的圖片名加載圖片image
? ? ? UIImage *image = [UIImage imageNamed:imageName];
? ? ? // ? ? ? ?將圖片image添加到數(shù)組images中
? ? ? [images addObject:image];
? }
? // ? 設置動畫圖片數(shù)組
? self.TomCatView.animationImages = images;
? // ?設置 動畫時長
? self.TomCatView.animationDuration = 26*0.075;
? // ? 重復次數(shù)
? self.TomCatView.animationRepeatCount = 1;
? // ? ?開始動畫
? [self.TomCatView startAnimating];
}
- (IBAction)sromachaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
? // ? ?創(chuàng)建可變數(shù)組images慢叨,負責存放要播放的圖片數(shù)組
? for (NSInteger i = 0; i < 34; i++) {
? ? ? // ? ? ? ?根據(jù)I來加載圖片,添加到可變數(shù)組IMAGES里面务蝠、
? ? ? // ? ? ? ?格式化圖片
? ? ? NSString *imageName = [NSString stringWithFormat:@"stomach_%02ld.jpg",i];
? ? ? // ? ? ? ?根據(jù)格式化的圖片名加載圖片image
? ? ? UIImage *image = [UIImage imageNamed:imageName];
? ? ? // ? ? ? ?將圖片image添加到數(shù)組images中
? ? ? [images addObject:image];
? }
? // ? 設置動畫圖片數(shù)組
? self.TomCatView.animationImages = images;
? // ?設置 動畫時長
? self.TomCatView.animationDuration = 34*0.075;
? // ? 重復次數(shù)
? self.TomCatView.animationRepeatCount = 1;
? // ? ?開始動畫
? [self.TomCatView startAnimating];
}
- (IBAction)rightatcion:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
? // ? ?創(chuàng)建可變數(shù)組images拍谐,負責存放要播放的圖片數(shù)組
? for (NSInteger i = 0; i < 30; i++) {
? ? ? // ? ? ? ?根據(jù)I來加載圖片,添加到可變數(shù)組IMAGES里面馏段、
? ? ? // ? ? ? ?格式化圖片
? ? ? NSString *imageName = [NSString stringWithFormat:@"footright_%02ld.jpg",i];
? ? ? // ? ? ? ?根據(jù)格式化的圖片名加載圖片image
? ? ? UIImage *image = [UIImage imageNamed:imageName];
? ? ? // ? ? ? ?將圖片image添加到數(shù)組images中
? ? ? [images addObject:image];
? }
? // ? 設置動畫圖片數(shù)組
? self.TomCatView.animationImages = images;
? // ?設置 動畫時長
? self.TomCatView.animationDuration = 30*0.075;
? // ? 重復次數(shù)
? self.TomCatView.animationRepeatCount = 1;
? // ? ?開始動畫
? [self.TomCatView startAnimating];
}
- (IBAction)leftaction:(UIButton *)sender {NSMutableArray *images = [NSMutableArray array];
? // ? ?創(chuàng)建可變數(shù)組images轩拨,負責存放要播放的圖片數(shù)組
? for (NSInteger i = 0; i < 30; i++) {
? ? ? // ? ? ? ?根據(jù)I來加載圖片,添加到可變數(shù)組IMAGES里面院喜、
? ? ? // ? ? ? ?格式化圖片
? ? ? NSString *imageName = [NSString stringWithFormat:@"footleft_%02ld.jpg",i];
? ? ? // ? ? ? ?根據(jù)格式化的圖片名加載圖片image
? ? ? UIImage *image = [UIImage imageNamed:imageName];
? ? ? // ? ? ? ?將圖片image添加到數(shù)組images中
? ? ? [images addObject:image];
? }
? // ? 設置動畫圖片數(shù)組
? self.TomCatView.animationImages = images;
? // ?設置 動畫時長
? self.TomCatView.animationDuration = 30*0.075;
? // ? 重復次數(shù)
? self.TomCatView.animationRepeatCount = 1;
? // ? ?開始動畫
? [self.TomCatView startAnimating];
}
- (void)didReceiveMemoryWarning {
? [super didReceiveMemoryWarning];
? // Dispose of any resources that can be recreated.
}
@end