//序列帧动画要播放的图片数组
// 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