1. 程式人生 > 實用技巧 >【iOS知識匯】動畫-CABasicAnimation

【iOS知識匯】動畫-CABasicAnimation

layer動畫。

CABasicAnimation--對應android 屬性動畫。

    //透明動畫。
CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"opacity"];

    

animation.beginTime = CACurrentMediaTime()+3;//開始時間

    animation.fromValue = @1.0;//開始值。
    animation.toValue = @0.1;//結束值 
    animation.duration = 2.0f
;//時長 animation.fillMode = kCAFillModeBackwards;//填充模式 self.myLabel.layer addAnimation:animation forKey:@"opacity" ];

可設定引數:1.時長。2反向播放3.開始時間 。4.重複次數。5.重複播放間隔。6.快慢。7.播完後行為。留在那裡還是移除。

/* The begin time of the object, in relation to its parent object, if
 * applicable. Defaults to 0. */

@property CFTimeInterval beginTime;
從什麼時候開始執行動畫。
/* The basic duration of the object. Defaults to 0. */ //動畫時長 @property CFTimeInterval duration; /* The rate of the layer. Used to scale parent time to local time, e.g. * if rate is 2, local time progresses twice as fast as parent time. * Defaults to 1. */ //執行時,相對速度。 @property float speed; /* Additional offset in active local time. i.e. to convert from parent * time tp to active local time t: t = (tp - begin) * speed + offset. * One use of this is to "pause" a layer by setting `speed' to zero and * `offset' to a suitable value. Defaults to 0.
*/ @property CFTimeInterval timeOffset; /* The repeat count of the object. May be fractional. Defaults to 0. */ @property float repeatCount;//重複次數 /* The repeat duration of the object. Defaults to 0. */ @property CFTimeInterval repeatDuration;//多入後重播。 /* When true, the object plays backwards after playing forwards. Defaults * to NO. */ @property BOOL autoreverses;//自動反向播放 /* Defines how the timed object behaves outside its active duration. * Local time may be clamped to either end of the active duration, or * the element may be removed from the presentation. The legal values * are `backwards', `forwards', `both' and `removed'. Defaults to * `removed'. */ @property(copy) CAMediaTimingFillMode fillMode;//填充模式 @end /* `fillMode' options. */ CA_EXTERN CAMediaTimingFillMode const kCAFillModeForwards//執行填充。動畫結束在哪兒就在哪兒。必須是不移除動畫。 API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)); CA_EXTERN CAMediaTimingFillMode const kCAFillModeBackwards//執行前就填充到相應位置或狀態。 API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)); CA_EXTERN CAMediaTimingFillMode const kCAFillModeBoth API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)); CA_EXTERN CAMediaTimingFillMode const kCAFillModeRemoved API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));


基本和android 一樣一樣的。