(CABasicAnimation)基本動畫

(CABasicAnimation)基本動畫

###基本動畫相關屬性動畫

  • fromValue:keyPath 相應屬性的初始值
  • byValue:keyPath相應屬性的中間值
  • toValue:keyPath相應屬性的結束值

動畫過程說明

  • 隨着動畫的進行,在長度爲duration的持續時間內,keyPath相應屬性的值從fromValue漸漸地變爲toValue;
  • KeyPath內容是CALayer的可動Animatable畫屬性
  • 若是fillMode=KCAFillModeForwards同時removedOnComletion=NO,那麼在動畫執行完畢後,圖層會保持顯示動畫執行後的狀態。但在實質上,圖層的屬性值仍是動畫執行前的初始值,並無真正被改變。

##一、平移 二、縮放 三、旋轉code

  • 平移

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
    animation.toValue = @320;
    animation.duration = 1;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = NO;
    
    [self.view.layer addAnimation:animation forKey:@"animation"];

###縮放orm

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    animation.toValue = @2;
    animation.duration = 0.25;
    animation.repeatCount = 1;
    animation.autoreverses = YES;
    
    [self.view.layer addAnimation:animation forKey:@"animation"];

###旋轉 *旋轉rem

- (CAAnimation *)rotationAnimation {
  CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animation.byValue = @( -2 * M_PI);//正數表示按照順時針旋轉,負數爲逆時針方向旋轉
    animation.duration = 2.0;
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = NO;
    animation.autoreverses = YES;
    animation.repeatCount = HUGE_VALF; //  HUGE_VALF 最大浮點數,表示無限次重複
    
    return animation;
}
相關文章
相關標籤/搜索