轉自 http://www.cocoachina.com/gamedev/2013/0122/5589.html
動畫效果提供了狀态或頁面轉換時流暢的使用者體驗,在ios系統中,咱們不需要自己編寫繪制動畫的代碼,core animation提供了豐富的api來實作你需要的動畫效果。
uikit隻用uiview來展示動畫,動畫支援uiview下面的這些屬性改變:
frame
bounds
center
transform
alpha
backgroundcolor
contentstretch
1、commitanimations方式使用uiview動畫
下面是點選改變後的效果(兩種):
動畫的常量有一下四種
1.2 交換本視圖控制器中2個view位置
[self.view exchangesubviewatindex:1 withsubviewatindex:0];
先添加兩個view ,一個redview 一個yellowview
這樣看起來就像兩頁一樣了。
1.3 、[uiview setanimationdidstopselector:@selector(animationfinish:)];
在commitanimations消息之前,可以設定動畫完成後的回調,設定方法是:
[uiview setanimationdidstopselector:@selector(animationfinish:)];
2、使用:catransition
transition.type 的類型可以有
淡化、推擠、揭開、覆寫
nsstring * const kcatransitionfade;
nsstring * const kcatransitionmovein;
nsstring * const kcatransitionpush;
nsstring * const kcatransitionreveal;
這四種,
transition.subtype
也有四種
nsstring * const kcatransitionfromright;
nsstring * const kcatransitionfromleft;
nsstring * const kcatransitionfromtop;
nsstring * const kcatransitionfrombottom;
2.2 私有的類型的動畫類型:
立方體、吸收、翻轉、波紋、翻頁、反翻頁、鏡頭開、鏡頭關。
下圖是第一個cube立方體的效果:
2.3 catransition的 startprogress endprogress屬性
這兩個屬性是float類型的。
可以控制動畫進行的過程,可以讓動畫停留在某個動畫點上,值在0.0到1.0之間。endprogress要大于等于startprogress。
比如上面的立方體轉到,可以設定endprogress= 0.5,讓動畫停留在轉動一般的位置。
上面這些私有的動畫效果,在實際應用中要謹慎使用。因為在app store稽核時可能會以為這些動畫效果而拒絕通過。
3、uiview的 + (void)animatewithduration
:(nstimeinterval)duration animations:(void (^)(void))animations completion:(void (^)(bool finished))completion
方法。
這個方法是在ios4.0之後才支援的。
比 1 裡的uiview的方法簡潔友善使用。
didview裡添加moveview。
然後用uiview animatewithduration動畫移動,移動動畫完畢後添加一個label。
3.2、 animatewithduration的嵌套使用
這個嵌套的效果是先把view變成透明,在從透明變成不透明,重複2.5次透明到不透明的效果。
文中例子的代碼:animatedemo