CAAnimation的一些坑

CAAnimation動(dòng)畫實(shí)際是加在layer上,在執(zhí)行完畢之后,動(dòng)畫效果就會(huì)消失,若要得到動(dòng)畫后的效果,需要加上兩個(gè)屬性

CGRect frame = view.frame;

view.transform = CGAffineTransformMakeTranslation(0.0, -CGRectGetMaxY(frame));

CABasicAnimation *trans = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];

trans.byValue = [NSNumber numberWithFloat:CGRectGetMaxY(frame)];

trans.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale.xy"];

scale.fromValue = @0.0;

scale.toValue = @1.0;

scale.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

CAAnimationGroup *group = [CAAnimationGroup animation];

group.animations = @[trans,scale];

group.duration = 0.3;

group.beginTime = CACurrentMediaTime() + animationOffset;

//動(dòng)畫執(zhí)行后的狀態(tài)模式

group.fillMode = kCAFillModeForwards;

//動(dòng)畫執(zhí)行后不刪除該狀態(tài)

group.removedOnCompletion = NO;

group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];


//設(shè)置動(dòng)畫的代理需要在加到layer之前

if (completion) {

//動(dòng)畫的delegate為強(qiáng)引用

group.delegate = self;//此delegate為strong

_CurrentComplete = completion;

}

[view.layer addAnimation:group forKey:kTranslateAndscale];



動(dòng)畫的代理為強(qiáng)引用,所以可能會(huì)引起retain circle

如果動(dòng)畫

group.removedOnCompletion = NO;

為yes時(shí),此時(shí)不存在問題,但是當(dāng)removedOnCompletion = NO;時(shí),此時(shí)應(yīng)該在視圖移除之前移除其動(dòng)畫。

CASpringAnimation的坑

在使用其他動(dòng)畫時(shí)

group.fillMode = kCAFillModeForwards;

//動(dòng)畫執(zhí)行后不刪除該狀態(tài)

group.removedOnCompletion = NO;

動(dòng)畫執(zhí)行完畢都會(huì)得到我們想要的結(jié)果,但是設(shè)置完CASpringAnimation的這兩個(gè)屬性后,動(dòng)畫執(zhí)行完畢,layer屬性的變化往往的不到我們想要的結(jié)果

/* The mass of the object attached to the end of the spring. Must be greater

than 0. Defaults to one. */

@property CGFloat mass;// 質(zhì)量

/* The spring stiffness coefficient. Must be greater than 0.

* Defaults to 100. */

@property CGFloat stiffness;//剛度,剛度是指材料或結(jié)構(gòu)在受力時(shí)抵抗彈性變形的能力

/* The damping coefficient. Must be greater than or equal to 0.

* Defaults to 10. */

@property CGFloat damping;//阻尼

/* The initial velocity of the object attached to the spring. Defaults

* to zero, which represents an unmoving object. Negative values

* represent the object moving away from the spring attachment point,

* positive values represent the object moving towards the spring

* attachment point. */

這三個(gè)屬性會(huì)影響到屬性的變化值。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,688評(píng)論 19 139
  • 在iOS實(shí)際開發(fā)中常用的動(dòng)畫無非是以下四種:UIView動(dòng)畫,核心動(dòng)畫,幀動(dòng)畫,自定義轉(zhuǎn)場(chǎng)動(dòng)畫。 1.UIView...
    請(qǐng)叫我周小帥閱讀 3,333評(píng)論 1 23
  • =========================================================...
    lavor閱讀 3,656評(píng)論 0 5
  • (我不知道是不是很多媽媽和我一樣,總是很容易被自己的孩子感動(dòng),總是覺得自己的孩子就是特別好的......) 這篇日...
    沐瓔閱讀 1,149評(píng)論 0 1
  • 4月21日,一早從瀘沽湖顛簸了4個(gè)多小時(shí)回到麗江古城,吃了黑山羊鍋,味道很贊,整個(gè)人就復(fù)活了。 因?yàn)椴惶矚g麗江的...
    劉芷睿閱讀 387評(píng)論 3 1

友情鏈接更多精彩內(nèi)容