//序列幀動畫要播放的圖片數組
// ???imageView.animationImages
//動畫時長
// ???imageView.animationDuration
//動畫重復次數
// ???imageView。animationRepeatCount
//開始動畫
// ???[imageView startAnimating]
//結束動畫
// ???[imageView stopAnimating]
//是否執行動畫
// ???[imageView isAnimating]
//序列幀動畫要播放的圖片數組
// ???imageView.animationImages
//動畫時長
// ???imageView.animationDuration
//動畫重復次數
// ???imageView。animationRepeatCount
//開始動畫
// ???[imageView startAnimating]
//結束動畫
// ???[imageView stopAnimating]
//是否執行動畫
// ???[imageView isAnimating]
例:湯姆貓動畫(1)
//
// ?ViewController.m
//湯姆貓
//
// ?Created by lanou on 16/7/12.
//?Copyright ? 2016年lanou. All rights reserved.
//
#import"ViewController.h"
@interfaceViewController()
@property(weak,nonatomic)IBOutletUIImageView*tomcatview;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
}
- (IBAction)eatBirdAction:(UIButton*)sender {
//創建可變數組
NSMutableArray*images = [NSMutableArrayarray];
for(NSIntegeri =0;i<40;i++) {
//根據i來加載圖片,然后添加到可變數組image里面
NSString*imageName = [NSStringstringWithFormat:@"eat_%02ld.jpg",i];
//根據格式化的圖片名加載圖片
UIImage*image = [UIImageimageNamed:imageName];
[imagesaddObject:image];
}
//設置動畫圖片數組
self.tomcatview.animationImages= images;
//設置動畫時長
self.tomcatview.animationDuration=40*0.075;
//設置動畫重復次數
self.tomcatview.animationRepeatCount=1;
//開始動畫
[self.tomcatviewstartAnimating];
}
(IBAction)drink:(UIButton*)sender {
NSMutableArray*images = [NSMutableArrayarray];
for(NSIntegeri =0;i<81;i++) {
//根據i來加載圖片,然后添加到可變數組image里面
NSString*imageName = [NSStringstringWithFormat:@"drink_%02ld.jpg",i];
UIImage*image = [UIImageimageNamed:imageName];
[imagesaddObject:image];
}
self.tomcatview.animationImages= images;
self.tomcatview.animationDuration=81*0.075;
self.tomcatview.animationRepeatCount=1;
[self.tomcatviewstartAnimating];
}
- (IBAction)cymbal:(UIButton*)sender {
NSMutableArray*images = [NSMutableArrayarray];
for(NSIntegeri =0;i<13;i++) {
//根據i來加載圖片,然后添加到可變數組image里面
NSString*imageName = [NSStringstringWithFormat:@"cymbal_%02ld.jpg",i];
UIImage*image = [UIImageimageNamed:imageName];
[imagesaddObject:image];
}
self.tomcatview.animationImages= images;
self.tomcatview.animationDuration=13*0.075;
self.tomcatview.animationRepeatCount=1;
[self.tomcatviewstartAnimating];
}
- (IBAction)fart:(UIButton*)sender {
NSMutableArray*images = [NSMutableArrayarray];
for(NSIntegeri =0;i<28;i++) {
//根據i來加載圖片,然后添加到可變數組image里面
NSString*imageName = [NSStringstringWithFormat:@"fart_%02ld.jpg",i];
UIImage*image = [UIImageimageNamed:imageName];
[imagesaddObject:image];
}
self.tomcatview.animationImages= images;
self.tomcatview.animationDuration=28*0.075;
self.tomcatview.animationRepeatCount=1;
[self.tomcatviewstartAnimating];
}
- (IBAction)pie:(UIButton*)sender {
NSMutableArray*images = [NSMutableArrayarray];
for(NSIntegeri =0;i<24;i++) {
//根據i來加載圖片,然后添加到可變數組image里面
NSString*imageName = [NSStringstringWithFormat:@"pie_%02ld.jpg",i];
UIImage*image = [UIImageimageNamed:imageName];
[imagesaddObject:image];
}
self.tomcatview.animationImages= images;
self.tomcatview.animationDuration=24*0.075;
self.tomcatview.animationRepeatCount=1;
self.tomcatviewstartAnimating];
}
- (IBAction)scratch:(UIButton*)sender {
NSMutableArray*images = [NSMutableArrayarray];
for(NSIntegeri =0;i<56;i++) {
//根據i來加載圖片,然后添加到可變數組image里面
NSString*imageName = [NSStringstringWithFormat:@"scratch_%02ld.jpg",i];
UIImage*image = [UIImageimageNamed:imageName];
[imagesaddObject:image];
}
self.tomcatview.animationImages= images;
self.tomcatview.animationDuration=56*0.075;
self.tomcatview.animationRepeatCount=1;
self.tomcatviewstartAnimating];
}
- (IBAction)footleft:(UIButton*)sender {
NSMutableArray*images = [NSMutableArrayarray];
for(NSIntegeri =0;i<30;i++) {
//根據i來加載圖片,然后添加到可變數組image里面
NSString*imageName = [NSStringstringWithFormat:@"footleft_%02ld.jpg",i];
UIImage*image = [UIImageimageNamed:imageName];
[imagesaddObject:image];
}
self.tomcatview.animationImages= images;
self.tomcatview.animationDuration=30*0.075;
self.tomcatview.animationRepeatCount=1;
[self.tomcatviewstartAnimating];
}
- (IBAction)footright:(UIButton*)sender {
NSMutableArray*images = [NSMutableArrayarray];
for(NSIntegeri =0;i<30;i++) {
//根據i來加載圖片,然后添加到可變數組image里面
NSString*imageName = [NSStringstringWithFormat:@"footright_%02ld.jpg",i];
UIImage*image = [UIImageimageNamed:imageName];
[imagesaddObject:image];
}
self.tomcatview.animationImages= images;
self.tomcatview.animationDuration=30*0.075;
self.tomcatview.animationRepeatCount=1;
[self.tomcatviewstartAnimating];
}
- (IBAction)stomach:(UIButton*)sender {
NSMutableArray*images = [NSMutableArrayarray];
for(NSIntegeri =0;i<34;i++) {
//根據i來加載圖片,然后添加到可變數組image里面
NSString*imageName = [NSStringstringWithFormat:@"stomach_%02ld.jpg",i];
UIImage*image = [UIImageimageNamed:imageName];
[imagesaddObject:image];
}
self.tomcatview.animationImages= images;
self.tomcatview.animationDuration=34*0.075;
self.tomcatview.animationRepeatCount=1;
[self.tomcatviewstartAnimating];
}
- (IBAction)angry:(UIButton*)sender {
NSMutableArray*images = [NSMutableArrayarray];
for(NSIntegeri =0;i<26;i++) {
//根據i來加載圖片,然后添加到可變數組image里面
NSString*imageName = [NSStringstringWithFormat:@"angry_%02ld.jpg",i];
UIImage*image = [UIImageimageNamed:imageName];
[imagesaddObject:image];
}
self.tomcatview.animationImages= images;
self.tomcatview.animationDuration=26*0.075;
self.tomcatview.animationRepeatCount=1;
[self.tomcatviewstartAnimating];
}
- (IBAction)knockout:(UIButton*)sender {
NSMutableArray*images = [NSMutableArrayarray];
for(NSIntegeri =0;i<81;i++) {
//根據i來加載圖片,然后添加到可變數組image里面
NSString*imageName = [NSStringstringWithFormat:@"knockout_%02ld.jpg",i];
UIImage*image = [UIImageimageNamed:imageName];
[imagesaddObject:image];
}
self.tomcatview.animationImages= images;
self.tomcatview.animationDuration=81*0.075;
self.tomcatview.animationRepeatCount=1;
[self.tomcatviewstartAnimating];
}
-(void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
例:湯姆貓動畫(2)
//
//? ViewController.m
//? 湯姆貓
//
//? Created by lanou on 16/7/12.
//? Copyright ?0?8 2016年 lanou. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *tomcatview;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)eatBirdAction:(UIButton *)sender {
[self tomCatAnimationWithName:@"eat" withCount:40];(調用編好的代碼組,方便快捷)
}
- (IBAction)drink:(UIButton *)sender {
[self tomCatAnimationWithName:@"drink" withCount:81];(調用編好的代碼組,方便快捷)
}
- (IBAction)cymbal:(UIButton *)sender {
[self tomCatAnimationWithName:@"cymbal" withCount:13];(調用編好的代碼組,方便快捷)
}
- (IBAction)fart:(UIButton *)sender {
[self tomCatAnimationWithName:@"fart" withCount:28];(調用編好的代碼組,方便快捷)
}
- (IBAction)pie:(UIButton *)sender {
[self tomCatAnimationWithName:@"pie" withCount:24];(調用編好的代碼組,方便快捷)
}
- (IBAction)scratch:(UIButton *)sender {
[self tomCatAnimationWithName:@"scratch" withCount:56];(調用編好的代碼組,方便快捷)
}
- (IBAction)footleft:(UIButton *)sender {
[self tomCatAnimationWithName:@"footleft" withCount:30];(調用編好的代碼組,方便快捷)
}
- (IBAction)footright:(UIButton *)sender {
[self tomCatAnimationWithName:@"footright" withCount:30];(調用編好的代碼組,方便快捷)
}
- (IBAction)stomach:(UIButton *)sender {
[self tomCatAnimationWithName:@"stomach" withCount:34];(調用編好的代碼組,方便快捷)
}
- (IBAction)angry:(UIButton *)sender {
[self tomCatAnimationWithName:@"angry" withCount:26];(調用編好的代碼組,方便快捷)
}
- (IBAction)knockout:(UIButton *)sender {
[self tomCatAnimationWithName:@"knockout" withCount:81];(調用編好的代碼組,方便快捷)
}
//代碼組
-(void)tomCatAnimationWithName:(NSString*)name withCount:(NSInteger)count
{
if([self.tomcatview isAnimating]){
return;
}
//創建可變數組
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0;i< count;i++) {
//? ? ? ? 根據i來加載圖片,然后添加到可變數組image里面
NSString *imageName = [NSString stringWithFormat:@"%@_%02ld.jpg",name,i];
//? ? ? 根據格式化的圖片名加載圖片
UIImage *image = [UIImage imageNamed:imageName];
[images addObject:image];
}
//? ? 設置動畫圖片數組
self.tomcatview.animationImages = images;
//? 設置動畫時長
self.tomcatview.animationDuration = count*0.075;
//? ? 設置動畫重復次數
self.tomcatview.animationRepeatCount = 1;
//? ? 開始動畫
[self.tomcatview startAnimating];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
//Dspose of any resources that can be recreated.
}
@end
//ViewController.m
//訪問系統相冊
//
//Created by lanou on 16/7/12.
//Copyright?0?8 2016年lanou.All rights reserved.
//
#import"ViewController.h"
//遵守協議
@interface ViewController()
@property(nonatomic,strong)UIButton*userBtn;
@end
@implementation? ViewController
-(void)viewDidLoad{
[superviewDidLoad];
//所有能看到的UI控件創建初始化方式都可以采用alloc initWithFrame
self.userBtn=[[UIButtonalloc]initWithFrame:CGRectMake(20,60,80,80)];
//設置顏色
self.userBtn.backgroundColor=[UIColorredColor];
//設置圓形半徑
self.userBtn.layer.cornerRadius=40;
self.userBtn.layer.masksToBounds=YES;
//添加點擊事件:去訪問系統相冊
[self.userBtnaddTarget:selfaction:@selector(setUserImage)forControlEvents:(UIControlEventTouchUpInside)];
//添加按鈕到屏幕上來
[self.viewaddSubview:self.userBtn];
}
//訪問系統相冊
-(void)setUserImage
{
//創建系統相冊
UIImagePickerController*imagePicker=[[UIImagePickerControlleralloc]init];
//設置代理,到@interface后面遵守協議
imagePicker.delegate=self;
//彈出系統相冊
[selfpresentViewController:imagePickeranimated:YEScompletion:nil];
}
//這個方法是協議UIImagePickerControllerDelegate里面的,選擇圖片結束的時候就會自動調用
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image editingInfo:(nullableNSDictionary
*)editingInfo
{
//設置頭像
[self.userBtnsetBackgroundImage:imageforState:(UIControlStateNormal)];
//將系統相冊消失
[pickerdismissViewControllerAnimated:YEScompletion:nil];
}
-(void)didReceiveMemoryWarning{
[superdidReceiveMemoryWarning];
//Dispose of any resources that can be recreated.
}
@end