ios學習筆記(三)簡單動畫

2021-07-06 07:45:32 字數 1816 閱讀 5211

先建立乙個uilabel

uilabel *label = [[uilabel alloc]initwithframe:cgrectmake(0,0,50,50)];

label.backgroundcolor = [uicolor bluecolor];

[self.window addsubview:label];

[uiview beginanimations:nil context:nil];

動畫開始

[uiview setanimationduration:4];

動畫持續時間

[uiview setanimationrepeatcount:1];

動畫重複次數

label.frame = cgrectmake(100, 100, 50, 50);

動畫結束是label的狀態

[uiview commitanimations];

提交動畫

上述動畫只進行了最基本的動畫設定,只改變了label的位置,執行時label將在4s的時間內從(0,0)移動到(100,100)

[uiview beginanimations:nil context:nil];

[uiview setanimationduration:4];

[uiview setanimationrepeatcount:1];

label.frame = cgrectmake(100, 100, 50, 50);

[uiview setanimationdelegate:self];

[uiview setanimationdidstopselector:@selector(whenstop)];

新增動畫結束之後的時間觸發,即四秒動畫執行完之後會執行whenstop方法

[uiview commitanimations];

這裡要提把這句拿出來看

[uiview beginanimations:nil context:nil];

beginanimation:動畫塊兒標示符,即給本次動畫命名可以傳遞給動畫結束方法引數為任意nsstring

context:用於傳遞引數,傳遞至動畫結束方法

-(void)animationdidstop:(nsstring *)animationid finished:(nsnumber *)finished context:(void *)context

指定動畫結束方法:animationid:動畫標示符,對應beginanimation的引數,用於區分哪個動畫塊兒呼叫此方法;finished:用於驗證動畫是否執行成功;context:用於接收動畫context傳過來的引數

若再次建立結束方法,需保持格式一致,如

-(void)anistop:(nsstring *)animationid finished:(nsnumber *)finished context:(void *)context

其他動畫效果

[uiview setanimationrepeatautoreverses:yes];

是否進行反項動畫

[uiview setanimationtransition:uiviewanimationtransitionflipfromleft forview:window  cache:yes];

頁面切換效果,寫在頁面切換之後可進行頁面切換效果設定,獲取window方式

[uiview setanimationcurve:uiviewanimationcurvelinear];

動畫切入和結束時是否減速的效果

幀動畫

iOS開發 簡單動畫筆記

今天因為工作需要,所以在ios試著做一些動畫特效 1.在簡單動畫中,要寫在兩行 之間 uiview beginanimations nilcontext null 動畫 在這裡裡面 uiview commitanimations 關於這兩行 我發現這兩行 關係到新的執行緒 在這兩行 之間的 可能還沒...

iOS開發學習之簡單動畫

原文 一 uiactivityindicatorview 1 屬性 isanimating屬性判斷是否正在動畫 2 第三方庫svprogresshud svprogresshud dismiss svprogresshud showwithstatus 網路載入中 masktype svprogre...

iOS學習 動畫

uiview動畫 改變uiview的frame ibaction changeframe id sender pragma mark uiviewanimationdelegate的 開始動畫方法 void animationwillstart nsstring animationid contex...