今天博主有一個隱式與顯式動畫的需求,遇到了一些困難點,在此和大家分享,希望能夠共同進步.
iOS開發中的動畫分為兩種:一種為UIView動畫,又稱隱式動畫,動畫后frame的數值發生了變化.另一種是CALayer動畫,又稱顯示動畫,動畫后模型層的數據不會發生變化,圖形回到原來的位置.但是在實際開發中,因為UIView可以相應用戶交互,所以UIView動畫用的多.
一.UIview的動畫
1.實現方式:動畫塊,block
begin
//設置動畫效果 修改屬性值,動畫時長等等
conmmit
2.屬性動畫,過渡動畫
①屬性動畫支持6種:transform 結構體 6個
②過渡動畫:容器視圖,兩個子視圖
二.CALayer動畫 == 核心動畫 == CAAnimation動畫
CAAnimation 抽象類
animation
①.CAAnimationGroup 組合動畫
②.CATransition 過渡動畫
③.CAPropertyAnimation 屬性動畫(layer的屬性)
animationWithKeyPath
CABasicAnimation 基本動畫
fromValue toValue
CAKeyFrameAnimation 關鍵幀動畫
values
下面貼出UIView動畫的代碼,與大家分享,CALayer動畫,也就是Core Animation各位看官可以自行百度.
1.
//使用動畫塊設置動畫
//開始設置動畫 第一個參數:動畫的名字 第二個參數:可以用來傳值
[UIView beginAnimations:@"哈哈" context:nil];
//設置動畫的時長
[UIView setAnimationDuration:1.5];
[UIView setAnimationRepeatAutoreverses:YES];
//根據需求設置視圖的屬性變化
_showView.backgroundColor=[UIColor grayColor];
_showView.center=CGPointMake(200, 200);
//提交動畫設置,開始執行動畫
[UIView commitAnimations];
2.
//使用Block設置動畫
[UIView animateWithDuration:1.5 animations:^{
//動畫效果設置
_showView.backgroundColor=[UIColor yellowColor];
//延時
[UIView setAnimationDelay:1.0];
//可以通過設置transform實現視圖移動
} completion:^(BOOL finished) {
//動畫完成后的設置
NSLog(@"動畫完成");
}];
http://www.cocoachina.com/cms/wap.php?plg_nld=1&action=article&id=7597&plg_auth=1&plg_uin=1&plg_dev=1&plg_nld=1&plg_usr=1&plg_vkey=1