IOS POP動(dòng)畫

參考鏈接一:基礎(chǔ)知識(shí)
參考鏈接二:很詳細(xì)的講解

參考鏈接二:演示代碼

參考鏈接三:POPAnimation 源碼倉庫

pop與coreanimation不同之處, 在于pop可以支持任何NSObeject對(duì)象,而coreanimation只支持CALayer

  • 增刪改查示例:
// 添加動(dòng)畫
POPSpringAnimation *anim = [POPSpringAnimation animation]; 
....
[layer pop_addAnimation:anim forKey:@"myKey"]; 
// 刪除動(dòng)畫
[layer pop_removeAnimationForKey:@"myKey"];
// 查詢&修改動(dòng)畫
anim = [layer animationForKey:@"myKey"];
if (anim){
anim.toValue = @(42.0);
}else{
....
}

一. 類型

Pop動(dòng)畫總共有4種類型,如下:

(一). Spring 彈性動(dòng)畫

POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
anim.toValue = [NSValue valueWithCGRect:CGRectMake(0,0,400,400)];
[layer pop_addAnimation:anim forKey:@"size"];

(二). Decay 衰減動(dòng)畫

POPDecayAnimation *anim = [POPDecayAnimation animationWithPropertyNamed:kPOPLayerPositionX];
anim.velocity = [NSValue valueWithCGPoint:CGPointMake(3,3)]; // 速度
[layer pop_addAnimation:anim forKey:@"slide"];

(三). Basic 基礎(chǔ)動(dòng)畫

POPBasicAnimation *anim = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.fromValue = @(0.0);
anim.toValue = @(1.0);
[view pop_addAnimation:anim forKey:@"fade"];

(四). Custom 自定義動(dòng)畫

// 占位

二. Properties 屬性設(shè)置

通過POPAnimatableProperty來設(shè)置具體屬性值

POPSpringAnimation *anim = [POPSpringAnimation animation];
anim.property = [POPAnimatableProperty propertyWithName:kPOPLayerBounds];

除了系統(tǒng)已經(jīng)提供的properties外,我們還可以定制自己的property

prop = [POPAnimatableProperty propertyWithName:@"com.foo.radio.volume" initializer:^(POPMutableAnimatableProperty *prop){
// get
prop.readBlock = ^(id obj, CGFloat values[]){
values[0] = [obj volume];
}

// set
prop.writeBlock = ^(id obj, const CGFloat values[]){
[obj setVolume:values[0]];

// dynamics threshold 動(dòng)畫開始
prop.threshold = 0.01; 
}
}];

anim.property = prop;

三. 五步創(chuàng)建POPAnimation

(一). 選擇類型:POPBasicAnimtaion , POPSpringAnimation, POPDecayAnimation

1. POPBasicAnimation

POPSpringAnimaton *anim = [POPSpringAnimation animaton];
basicAnimation.timingFunciton = [CAMediaTimingFunciton functionWithName:kCAMediaTimingFunctionLinear];

kCAMediaTimingFunctionLinear kCAMediaTimingFunctionEaseIn
kCAMediaTimingFunctionEaseOut kCAMediaTimingFunctionEaseInEaseOut

2. POPSpringAnimation

POPSpringAnimation *springAnimation = [POPSpringAnimation animation];
springAnimation.velocity = @(1000); // 速率
sprngAnimation.springBounciness = 14; // 彈簧彈力:晃動(dòng)的幅度,[0-20, 默認(rèn)為4]
springAnimation.springSpeed = 3; // 彈簧速度 [0-20,默認(rèn)為12] 
springAnimation.dynamicsMass = 3; // 彈簧質(zhì)量
springAnimation.dynamicsTension = 7;  // 彈簧張力
springAnimation.dynamicsFriction = 700; // 彈簧摩擦

3. POPDecayAnimation

POPDecayAniamtion *decayAnimation = [POPDecayAnimation animation];
decayAnimation.velocity = @(233);
decayAnimation.deceleration = 0.833;  [0-1] // 減速

(二). 屬性設(shè)置: properties

  • View: kPOPViewAlpha, kPOPViewBackgroundColor, kPOPViewBounds,
    kPOPViewCenter, kPOPViewFrame, kPOPViewScaleXY, kPOPViewSizer

  • Layer: kPOPLayerBackgroundColor, kPOPLayerBounds, kPOPLayerScaleXY,
    kPOPLayerSize, kPOPLayerOpacity, kPOPLayerPositionX, kPOPLayerPositionY, kPopLayerRotation

anim.property = [POPAnimationProperty propertyWithName:kPOPViewFrame];

(三). 設(shè)置改變值: toValue

  • anim.toValue = @(1.0); // alpha, opacity, positionX, positionY,rotation(M_PI/4)
  • anim.toValue = [UIColor redColor]; // color
  • anim.toValue = [NSValue valueWithCGPoint:CGPointMake(200,200)]; center,position
  • anim.toValue = [NSValue valueWithCGRect:CGRectMake(0,0,400,400)];
  • anim.toValue = [NSValue valueWithCGSize:CGSizeMake(40,40)]; // size,bounds,frame,scaleXY
anim.toValue  = [NSValue valueWithCRGectMake(0,0,90,100)];

(四). 命名&回調(diào)

anim.name = @"PopFrameAnim";
anim.completionBlock = ^(POPAnimation *anim, BOOL finished){

};
// 或者代理: <POPAnimatorDelegate>
- (void)pop_animationDidStart:(POPAnimation *)anim; 
- (void)pop_animationDidStop:(POPAnimation *)anim finished:(BOOL)finished;
- (void)pop_animationDidReachToValue:(POPAnimation *)anim;

(五). 添加

[view pop_addAnimation: anim forKey:@"PopFrameAnim"];
最后編輯于
?著作權(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),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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