標籤:旋轉 min erp uiimage named nil 時間長度 建立 主要畫面格
Core Animation
基本3種動畫:基本動畫CABasicAnimation、 主要畫面格動畫CAKeyframeAnimation、 轉場動畫CATransition
還有就是動畫組:CAAnimationGroup
一、基本動畫CABasicAnimation的使用:
CABasicAnimation * animation = [CABasicAnimation animation]; //相應屬性的值 如:transform.scale(縮放)、 transform.rotation.z(z軸,做旋轉的時候)。。。 animation.keyPath = keyPath; animation.toValue = toValue;//如改變縮放結束時的值 toValue = @0.5 、旋轉角度 toValue = @(M_PI) animation.repeatCount = MAXFLOAT; // 設定動畫完成的時候不要移除動畫 animation.removedOnCompletion = NO; //設定動畫執行完成要保持最新的效果 animation.fillMode = kCAFillModeForwards; /* duration 動畫時間長度 repeatCount 動畫迴圈次數 repeatDuration 動畫時間 timingFunction 動畫的速度變化 fromValue 所改變屬性的起始值 toValue 所改變屬性的結束時的值 */
//添加到對應的view的layer層上
[view.layer addAnimation:animation forKey:nil];
二、主要畫面格動畫CAKeyframeAnimation
1、類比iOS系統刪除應用晃動的動畫
CAKeyframeAnimation * rotation = [CAKeyframeAnimation animation]; //相應屬性 rotation.keyPath = @"transform.rotation"; //每個主要畫面格 改變屬性的值 rotation.values = @[@(TORADION(-5)),@(TORADION(5)),@(TORADION(-5))]; rotation.repeatCount = MAXFLOAT; //添加到相應的view的layer上 [view.layer addAnimation:rotation forKey:nil];
2、運動軌跡
//建立一個路徑 或者得到一個路徑 UIBezierPath * bezierPath = [UIBezierPath bezierPath]; [bezierPath moveToPoint:CGPointMake(0, 400)]; [bezierPath addLineToPoint:CGPointMake(50, 300)]; [bezierPath addLineToPoint:CGPointMake(100, 400)]; [bezierPath addLineToPoint:CGPointMake(200, 300)]; [bezierPath addLineToPoint:CGPointMake(250, 400)]; [bezierPath addLineToPoint:CGPointMake(300, 250)]; [bezierPath addLineToPoint:CGPointMake(330, 350)]; [bezierPath addLineToPoint:CGPointMake(380, 300)]; [bezierPath addLineToPoint:CGPointMake(450, 400)]; CAKeyframeAnimation * position = [CAKeyframeAnimation animation]; position.keyPath = @"position"; //動畫移動路徑 position.path = bezierPath.CGPath; position.repeatCount = MAXFLOAT; position.duration = 3; //添加到對應的view的layer上 [view.layer addAnimation:rotation forKey:nil];
三、轉場動畫CATransition
轉場動畫一定要在轉場的時候使用才有效,如:改變UIImageView的圖片
//改變ImageView.image的時候(轉場) _imageView.image = [UIImage imageNamed:img]; CATransition *atransition = [CATransition animation]; //類型 atransition.type = @"rippleEffect"; atransition.duration = 1;
//添加到_imageView的layer上 [_imageView.layer addAnimation:atransition forKey:nil]; /* 類型 1.#define定義的常量 kCATransitionFade 交叉淡化過渡 kCATransitionMoveIn 新視圖移到舊視圖上面 kCATransitionPush 新視圖把舊視圖推出去 kCATransitionReveal 將舊視圖移開,顯示下面的新視圖 2.用字串表示 pageCurl 向上翻一頁 pageUnCurl 向下翻一頁 rippleEffect 滴水效果 suckEffect 收縮效果,如一塊布被抽走 cube 立方體效果 oglFlip 上下翻轉效果 */
四、動畫組CAAnimationGroup
這個很簡單,就是把幾個動畫放到一個數組中去執行動畫
// 同時縮放,平移,旋轉 //建立一個動畫組 CAAnimationGroup *group = [CAAnimationGroup animation]; //縮放 CABasicAnimation *scale = [CABasicAnimation animation]; scale.keyPath = @"transform.scale"; scale.toValue = @0.5; //旋轉 CABasicAnimation *rotation = [CABasicAnimation animation]; rotation.keyPath = @"transform.rotation"; rotation.toValue = @(arc4random_uniform(M_PI)); //平移 CABasicAnimation *position = [CABasicAnimation animation]; position.keyPath = @"position"; position.toValue = [NSValue valueWithCGPoint:CGPointMake(arc4random_uniform(200), arc4random_uniform(200))]; //添加到動畫組 group.animations = @[scale,rotation,position]; //添加到相應的view的layer上 [view.layer addAnimation:group forKey:nil];
簡單介紹 不好 勿噴。
iOS Core Animation