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"];

//創(chuàng)建并初始化按鈕圖片及文本

//表明文本的位置

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

//文本內(nèi)容

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"];

//左按鈕的背景及按下狀態(tài)

[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];

//創(chuàng)立按鈕監(jiān)聽

[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{

//左邊按鈕和右邊按鈕都是在一個正常狀態(tài)下

//打開交互

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;

//獲取后一張圖片的圖片內(nèi)容

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{

//左右兩邊按鈕都是正常狀態(tài)

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;

//獲取前一張圖片的圖片內(nèi)容

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];

//序列成動畫要播放的圖片數(shù)組

// ???imageView.animationImages

//動畫時長

// ???imageView.animationDuration

//動畫重復次數(shù)

// ???imageView.animationRepeatCount

//開始動畫

// ???[imageView startAnimating];

//結束動畫

// ???[imageView stopAnimating];

//是否正在執(zhí)行動畫

// ???[imageView ?isAnimating];

}

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

[selfsetTomCatAnimationWithName:@"eat"withCount:40];

/*

//創(chuàng)建可變數(shù)組images茅坛,負責存放要播放的圖片數(shù)組

NSMutableArray ?*images=[NSMutableArray ??array];

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]; ?*/

}

-(void)setTomCatAnimationWithName:

(NSString*)name ??withCount:(NSInteger)count

{

//判斷該動畫是否正在執(zhí)行

if([self.tomCatViewisAnimating]) {

return;

}

//創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組

NSMutableArray*images=[NSMutableArrayarray];

for(NSIntegeri=0; i

//根據(jù)i來加載圖片,然后添加到可變數(shù)組images里面

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

//根據(jù)格式化的圖片名加載圖片image

UIImage*image=[UIImageimageNamed:imageName];

//將圖片image添加到數(shù)組images中

[imagesaddObject:image];

}

//設置動畫圖片數(shù)組

self.tomCatView.animationImages=images;

//設置動畫時長

self.tomCatView.animationDuration=count*0.075;

//設置動畫重復次數(shù)

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?????

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌脆丁,老刑警劉巖,帶你破解...
    沈念sama閱讀 207,113評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件动雹,死亡現(xiàn)場離奇詭異槽卫,居然都是意外死亡,警方通過查閱死者的電腦和手機胰蝠,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,644評論 2 381
  • 文/潘曉璐 我一進店門歼培,熙熙樓的掌柜王于貴愁眉苦臉地迎上來震蒋,“玉大人,你說我怎么就攤上這事躲庄〔槠剩” “怎么了?”我有些...
    開封第一講書人閱讀 153,340評論 0 344
  • 文/不壞的土叔 我叫張陵噪窘,是天一觀的道長笋庄。 經(jīng)常有香客問我,道長倔监,這世上最難降的妖魔是什么直砂? 我笑而不...
    開封第一講書人閱讀 55,449評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮丐枉,結果婚禮上哆键,老公的妹妹穿的比我還像新娘掘托。我一直安慰自己瘦锹,他們只是感情好,可當我...
    茶點故事閱讀 64,445評論 5 374
  • 文/花漫 我一把揭開白布闪盔。 她就那樣靜靜地躺著弯院,像睡著了一般。 火紅的嫁衣襯著肌膚如雪泪掀。 梳的紋絲不亂的頭發(fā)上听绳,一...
    開封第一講書人閱讀 49,166評論 1 284
  • 那天,我揣著相機與錄音异赫,去河邊找鬼椅挣。 笑死,一個胖子當著我的面吹牛塔拳,可吹牛的內(nèi)容都是我干的鼠证。 我是一名探鬼主播,決...
    沈念sama閱讀 38,442評論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼靠抑,長吁一口氣:“原來是場噩夢啊……” “哼量九!你這毒婦竟也來了?” 一聲冷哼從身側響起颂碧,我...
    開封第一講書人閱讀 37,105評論 0 261
  • 序言:老撾萬榮一對情侶失蹤荠列,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后载城,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體肌似,經(jīng)...
    沈念sama閱讀 43,601評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,066評論 2 325
  • 正文 我和宋清朗相戀三年诉瓦,在試婚紗的時候發(fā)現(xiàn)自己被綠了川队。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片受楼。...
    茶點故事閱讀 38,161評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖呼寸,靈堂內(nèi)的尸體忽然破棺而出艳汽,到底是詐尸還是另有隱情,我是刑警寧澤对雪,帶...
    沈念sama閱讀 33,792評論 4 323
  • 正文 年R本政府宣布河狐,位于F島的核電站,受9級特大地震影響瑟捣,放射性物質發(fā)生泄漏馋艺。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,351評論 3 307
  • 文/蒙蒙 一迈套、第九天 我趴在偏房一處隱蔽的房頂上張望捐祠。 院中可真熱鬧,春花似錦桑李、人聲如沸踱蛀。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,352評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽率拒。三九已至,卻和暖如春禁荒,著一層夾襖步出監(jiān)牢的瞬間猬膨,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,584評論 1 261
  • 我被黑心中介騙來泰國打工呛伴, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留勃痴,地道東北人。 一個月前我還...
    沈念sama閱讀 45,618評論 2 355
  • 正文 我出身青樓热康,卻偏偏與公主長得像沛申,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子褐隆,可洞房花燭夜當晚...
    茶點故事閱讀 42,916評論 2 344

推薦閱讀更多精彩內(nèi)容

  • UI常用控件 // // ViewController.m // UI常用控件 // // Created by ...
    小玉柚子閱讀 249評論 0 0
  • // //ViewController.m //UI常用控件 // //Created by lanou on 1...
    BlueLantern閱讀 223評論 0 0
  • 簡單的介紹了OC語言的用途和歷史污它,是一種基于蘋果產(chǎn)品——IOS系統(tǒng)產(chǎn)品的編程語言,能夠智能有效的寫出符合而實...
    圍籬亦海莊閱讀 302評論 0 1
  • 1.oc基本語法 // // main.m // oc基本語法 // // Created by lanou on...
    GOT_HODOR閱讀 414評論 0 0
  • 今天的學習的是Oc中控件的學習庶弃,先是對控件方法的了解衫贬,然后是在代碼板上寫代碼,實現(xiàn)在界面上圖片的轉換歇攻,還有是對按鈕...
    葉家的大樹苗閱讀 246評論 0 0