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

//

//  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���̧�

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 210,978评论 6 490
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 89,954评论 2 384
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 156,623评论 0 345
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,324评论 1 282
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,390评论 5 384
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,741评论 1 289
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,892评论 3 405
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,655评论 0 266
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,104评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,451评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,569评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,254评论 4 328
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,834评论 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,725评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,950评论 1 264
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,260评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,446评论 2 348

推荐阅读更多精彩内容

  • UI常用控件 // // ViewController.m // UI常用控件 // // Created by ...
    小玉柚子阅读 251评论 0 0
  • // //ViewController.m //UI常用控件 // //Created by lanou on 1...
    BlueLantern阅读 223评论 0 0
  • 简单的介绍了OC语言的用途和历史,是一种基于苹果产品——IOS系统产品的编程语言,能够智能有效的写出符合而实...
    围篱亦海庄阅读 312评论 0 1
  • 1.oc基本语法 // // main.m // oc基本语法 // // Created by lanou on...
    GOT_HODOR阅读 417评论 0 0
  • 今天的学习的是Oc中控件的学习,先是对控件方法的了解,然后是在代码板上写代码,实现在界面上图片的转换,还有是对按钮...
    叶家的大树苗阅读 248评论 0 0