IOS開發基礎之大轉盤案例

2021-10-20 15:16:55 字數 2501 閱讀 6073

本案例使用xib載入的,以及核心動畫的使用。動態按鈕的使用和建立。等知識。

// 37-大轉盤

//// created by 魯軍 on 2021/2/27.

//#import

@inte***ce ljrotateview : uiview

+(instancetype)rotateview;-(

void

)startrotate;

@end

//

// ljrotateview.m

// 37-大轉盤

//// created by 魯軍 on 2021/2/27.

//#import "ljrotateview.h"

@inte***ce ljrotateview (

)@property

(weak, nonatomic) iboutlet uiimageview *rotateimage;

//鋸齒

@property

(nonatomic,weak)uibutton *currentbutton;

@property

(nonatomic,strong)cadisplaylink *link;

-(ibaction)picknumber:

(id)sender;

@end

@implementation ljrotateview-(

void

)startrotate

//1 秒呼叫60s-(

void

)rotate

+(instancetype)rotateview-(

void

)awakefromnib}-

(void

)btnclick:

(uibutton *

)sender-(

void

)layoutsubviews}-

(uiimage*

)clipimagewithimage:

(uiimage *

)image withindex:

(nsinteger)index

-(ibaction)picknumber:

(id)sender

self

.link.paused = yes;

cabasicanimation *anim=

[[cabasicanimation alloc] init]

;

anim.keypath =

@"transform.rotation"

;//計算 需要減去的角度

cgfloat angle =

2*m_pi /12*

self

.currentbutton.tag;

anim.tovalue =@(

5*m_pi*

2- angle)

;//圈

anim.duration =3;

//設定時間

anim.fillmode =kcafillmodeforwards;

anim.removedoncompletion=no;

[self

.rotateimage.layer addanimation:anim forkey:

@"keys"];

dispatch_after

(dispatch_time

(dispatch_time_now,

(int64_t)

(anim.duration * nsec_per_sec)),

dispatch_get_main_queue()

,^);

}-(void

)alertview:

(uialertview *

)alertview clickedbuttonatindex:

(nsinteger)buttonindex

@end

//

// viewcontroller.m

// 37-大轉盤

//// created by 魯軍 on 2021/2/27.

//#import "viewcontroller.h"

#import "ljrotateview.h"

@inte***ce viewcontroller (

)@end

@implementation viewcontroller-(

void

)viewdidload

-(bool)prefersstatusbarhidden

@end

iOS開發基礎

1 乙個應用程式是怎麼啟動的?當我們基於xcode模版建立應用程式時,應用程式啟動時大部分的環境引數會被自動設定。uikit框架提供了乙個應用程式需要構建和管理它的使用者介面的所有類 啟動 結束應用程式,控制介面和觸點事件 uikit是cocoa touch提供的眾多物件導向框架中的乙個。cocoa...

iOS開發基礎 UIButton

今天開始寫ios開發基礎,自己要開始做乙個專案,好用來找第乙份實習工作,開始記錄我學習ios開發的過程。以下是寫在viewcontroller.m檔案下的。viewcontroller.m 01 button created by linjia on 15 8 22.import viewcontr...

iOS開發控制項基礎

一 使用plist檔案 使用plist檔案的目的 將資料和 分離。載入方法 nsstring path nsbundle mainbundle pathforresource imagedata oftype plist nsarray imagelist nsarray arraywithcont...