IOS 核心動畫之CAKeyframeAnimation

來源:互聯網
上載者:User

標籤:color   使用   width   os   cti   for   

- IOS 核心動畫之CAKeyframeAnimation
- 簡單介紹
是CApropertyAnimation的子類,跟CABasicAnimation的區別是:CABasicAnimation只能從一個數值(fromValue)變到另一個數值(toValue),而CAKeyframeAnimation會使用一個NSArray儲存這些數值
- 屬性解析:
- values:就是上述的NSArray對象。裡面的元素稱為”主要畫面格”(keyframe)。動畫對象會在指定的時間(duration)內,依次顯示values數組中的每一個主要畫面格
- path:可以設定一個CGPathRef\CGMutablePathRef,讓層跟著路徑移動。path只對CALayer的anchorPoint和position起作用。如果你設定了path,那麼values將被忽略
- keyTimes:可以為對應的主要畫面格指定對應的時間點,其取值範圍為0到1.0,keyTimes中的每一個時間值都對應values中的每一幀.當keyTimes沒有設定的時候,各個主要畫面格的時間是平分的
- 說明:CABasicAnimation可看做是最多隻有2個主要畫面格的CAKeyframeAnimation
- Values方式:
- CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
animation.keyPath = @"position";
NSValue *value1=[NSValue valueWithCGPoint:CGPointMake(100, 100)];
NSValue *value2=[NSValue valueWithCGPoint:CGPointMake(200, 100)];
NSValue *value3=[NSValue valueWithCGPoint:CGPointMake(200, 200)];
NSValue *value4=[NSValue valueWithCGPoint:CGPointMake(100, 200)];
NSValue *value5=[NSValue valueWithCGPoint:CGPointMake(100, 100)];
[email protected][value1,value2,value3,value4,value5]; animation.repeatCount=MAXFLOAT;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.duration = 4.0f;
animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.delegate=self;
[self.myView.layer addAnimation:animation forKey:nil];
- Path方式:
- CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
animation.keyPath = @"position";
CGMutablePathRef path=CGPathCreateMutable();
CGPathAddEllipseInRect(path, NULL, CGRectMake(150, 100, 100, 100));
animation.path=path;
CGPathRelease(path);
animation.repeatCount=MAXFLOAT;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.duration = 4.0f;
animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.delegate=self;
[self.myView.layer addAnimation:animation forKey:nil];

- keyPath可以使用的key
- #define angle2Radian(angle) ((angle)/180.0*M_PI)
- transform.rotation.x 圍繞x軸翻轉 參數:角度 angle2Radian(4)
transform.rotation.y 圍繞y軸翻轉 參數:同上
transform.rotation.z 圍繞z軸翻轉 參數:同上
transform.rotation 預設圍繞z軸
transform.scale.x x方向縮放 參數:縮放比例 1.5
transform.scale.y y方向縮放 參數:同上
transform.scale.z z方向縮放 參數:同上
transform.scale 所有方向縮放 參數:同上
transform.translation.x x方向移動 參數:x軸上的座標 100
transform.translation.y x方向移動 參數:y軸上的座標
transform.translation.z x方向移動 參數:z軸上的座標
transform.translation 移動 參數:移動到的點 (100,100)
opacity 透明度 參數:透明度 0.5
backgroundColor 背景顏色 參數:顏色 (id)[[UIColor redColor] CGColor]
cornerRadius 圓角 參數:圓角半徑 5
borderWidth 邊框寬度 參數:邊框寬度 5
bounds 大小 參數:CGRect
contents 內容 參數:CGImage
contentsRect 可視內容 參數:CGRect 值是0~1之間的小數
hidden 是否隱藏
position
shadowColor
shadowOffset
shadowOpacity
shadowRadius
*

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.