oc语言的学习笔记整理:可视化编程(序列成动画)

2016-07-12  本文已影响0人  近视眼姑娘

//

//  ViewController.m

//  ui常用控件

//

//  Created by lanou on 16/7/10.

//  Copyright © 2016年pingguo. All rights reserved.

//

#import"ViewController.h"

@interfaceViewController()

@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

@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

self.imageNames=@[@"biaoqingdi",@"bingli",@"chiniupa",@"danteng",@"wangba"];

//创建并初始化按钮图片及文本

//表明文本的位置

self.titleLabel=[[UILabelalloc]initWithFrame:CGRectMake(160,60,150,30)];

//文本内容

self.titleLabel.text=@"biaoqingdi";

//将文本添加到视图

[self.viewaddSubview:self.titleLabel];

//表明左按钮的位置

self.leftBtn=[[UIButtonalloc]initWithFrame:CGRectMake(20,150,45,45)];

//关掉交互

self.leftBtn.userInteractionEnabled=NO;

//加载左按钮的图片

UIImage*leftImage=[UIImageimageNamed:@"left_disable"];

//左按钮的背景及按下状态

[self.leftBtnsetBackgroundImage:leftImageforState:(UIControlStateNormal)];

//将左按钮添加到视图

[self.viewaddSubview:self.leftBtn];

//表明图片的位置

self.myImageView=[[UIImageViewalloc]initWithFrame:CGRectMake(85,100,200,200)];

//加载图片

UIImage*image=[UIImageimageNamed:@"biaoqingdi"];

//设置myimageview显示的图片

self.myImageView.image=image;

//将图片添加到视图

[self.viewaddSubview:self.myImageView];

//以下同理

self.rightBtn=[[UIButtonalloc]initWithFrame:CGRectMake(305,150,45,45)];

UIImage*rightImage=[UIImageimageNamed:@"right_normal"];

[self.rightBtnsetBackgroundImage:rightImageforState:(UIControlStateNormal)];

[self.viewaddSubview:self.rightBtn];

//创立按钮监听

[self.rightBtnaddTarget:selfaction:@selector(rightBtnAction)forControlEvents:(UIControlEventTouchUpInside)];

[self.leftBtnaddTarget:selfaction:@selector(leftBtnAction)forControlEvents:(UIControlEventTouchUpInside)];

}

-(void)rightBtnAction

{

//切换到下一张图片

//获取当前是第几张图片

NSIntegerindex=[self.imageNamesindexOfObject:self.titleLabel.text];

//不是为最后一张才切换到下一张

if(index<4) {

if(index==3) {

//改变右边按钮的颜色和关闭交互

self.rightBtn.userInteractionEnabled=NO;

UIImage*image=[UIImageimageNamed:@"right_disable"];

[self.rightBtnsetBackgroundImage:imageforState:(UIControlStateNormal)];

}

else{

//左边按钮和右边按钮都是在一个正常状态下

//打开交互

self.leftBtn.userInteractionEnabled=YES;

self.rightBtn.userInteractionEnabled=YES;

UIImage*leftNormal=[UIImageimageNamed:@"left_normal"];

UIImage*rightNormal=[UIImageimageNamed:@"right_normal"];

[self.leftBtnsetBackgroundImage:leftNormalforState:(UIControlStateNormal)];

[self.rightBtnsetBackgroundImage:rightNormalforState:(UIControlStateNormal)];

}

//将当前图片与下一张图片连接起来

NSString*nextTitle=self.imageNames[index+1];

//获取后一张图片的标签

self.titleLabel.text=nextTitle;

//获取后一张图片的图片内容

self.myImageView.image=[UIImageimageNamed:nextTitle];

}

}

-(void)leftBtnAction

{

//切换到前一张图片

//获取当前是第几张图片

NSIntegerindex=[self.imageNamesindexOfObject:self.titleLabel.text];

//不是为第一张才切换到前一张

if(index>0) {

if(index==1) {

//左边按钮交互关闭,图片切换

self.leftBtn.userInteractionEnabled=NO;

UIImage*image=[UIImageimageNamed:@"left_disable"];

[self.leftBtnsetBackgroundImage:imageforState:(UIControlStateNormal)];

}

else{

//左右两边按钮都是正常状态

self.leftBtn.userInteractionEnabled=YES;

self.rightBtn.userInteractionEnabled=YES;

UIImage*leftNormal=[UIImageimageNamed:@"left_normal"];

UIImage*rightNormal=[UIImageimageNamed:@"right_normal"];

[self.leftBtnsetBackgroundImage:leftNormalforState:(UIControlStateNormal)];

[self.rightBtnsetBackgroundImage:rightNormalforState:(UIControlStateNormal)];

}

//将当前图片与前一张图片连接起来

NSString*beforeTitle=self.imageNames[index-1];

//获取前一张图片的标签

self.titleLabel.text=beforeTitle;

//获取前一张图片的图片内容

self.myImageView.image=[UIImageimageNamed:beforeTitle];

}

}

-(void)btnClickLister

{NSLog(@"click btn");

}

-(void)demo {//按钮UIButton

//    UIButton  *button=[UIButton buttonWithType:UIButtonTypeInfoDark];

UIButton*button=[[UIButtonalloc]initWithFrame:CGRectMake(50,50,80,80)];

// frame表明了控件的

[buttonsetTitle:@"眼镜哥"forState:UIControlStateNormal];

UIImage*image=[UIImageimageNamed:@"right_normal"];

[buttonsetBackgroundImage:imageforState:UIControlStateNormal];

button.backgroundColor=[UIColorredColor];

[buttonaddTarget:selfaction:@selector(btnClickLister)forControlEvents:UIControlEventTouchUpOutside];

//添加

[self.viewaddSubview:button];

UIImageView*imageView=[[UIImageViewalloc]initWithFrame:CGRectMake(150,50,200,200)

];

UIImage*image1=[UIImageimageNamed:@"biaoqingdi"];

imageView.image=image1;

[self.viewaddSubview:imageView];

UILabel*label=[[UILabelalloc]initWithFrame:CGRectMake(150,270,150,30)];

label.text=@"表情弟";

label.textAlignment=NSTextAlignmentCenter;

label.textColor=[UIColorredColor];

[self.viewaddSubview:label];

}

@end

//

//  ViewController.m

//汤姆猫

//

//  Created by lanou on 16/7/12.

//  Copyright © 2016年pingguo. All rights reserved.

//

#import"ViewController.h"

@interfaceViewController()

@property(weak,nonatomic)IBOutletUIImageView*tomCatView;

@end

@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

//    UIImageView  *imageView=[UIImageView  new];

//序列成动画要播放的图片数组

//    imageView.animationImages

//动画时长

//    imageView.animationDuration

//动画重复次数

//    imageView.animationRepeatCount

//开始动画

//    [imageView startAnimating];

//结束动画

//    [imageView stopAnimating];

//是否正在执行动画

//    [imageView  isAnimating];

}

- (IBAction)eatBirdAction:(UIButton*)sender {

[selfsetTomCatAnimationWithName:@"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.tomCatViewisAnimating]) {

return;

}

//创建可变数组images,负责存放要播放的图片数组

NSMutableArray*images=[NSMutableArrayarray];

for(NSIntegeri=0; i

//根据i来加载图片,然后添加到可变数组images里面

NSString*imageName=[NSStringstringWithFormat:@"%@_%02ld.jpg",name,i];

//根据格式化的图片名加载图片image

UIImage*image=[UIImageimageNamed:imageName];

//将图片image添加到数组images中

[imagesaddObject:image];

}

//设置动画图片数组

self.tomCatView.animationImages=images;

//设置动画时长

self.tomCatView.animationDuration=count*0.075;

//设置动画重复次数

self.tomCatView.animationRepeatCount=1;

//开始动画

[self.tomCatViewstartAnimating];

}

- (IBAction)drink:(UIButton*)sender {

[selfsetTomCatAnimationWithName:@"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 {

[selfsetTomCatAnimationWithName:@"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 {

[selfsetTomCatAnimationWithName:@"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 {

[selfsetTomCatAnimationWithName:@"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 {

[selfsetTomCatAnimationWithName:@"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 {

[selfsetTomCatAnimationWithName:@"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 {

[selfsetTomCatAnimationWithName:@"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 {

[selfsetTomCatAnimationWithName:@"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 {

[selfsetTomCatAnimationWithName:@"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 {

[selfsetTomCatAnimationWithName:@"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 {

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

p���̧�

上一篇 下一篇

猜你喜欢

热点阅读