pop與coreanimation不同之處, 在于pop可以支持任何NSObeject對象,而coreanimation只支持CALayer
- 增刪改查示例:
// 添加動畫
POPSpringAnimation *anim = [POPSpringAnimation animation];
....
[layer pop_addAnimation:anim forKey:@"myKey"];
// 刪除動畫
[layer pop_removeAnimationForKey:@"myKey"];
// 查詢&修改動畫
anim = [layer animationForKey:@"myKey"];
if (anim){
anim.toValue = @(42.0);
}else{
....
}
一. 類型
Pop動畫總共有4種類型,如下:
(一). Spring 彈性動畫
POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
anim.toValue = [NSValue valueWithCGRect:CGRectMake(0,0,400,400)];
[layer pop_addAnimation:anim forKey:@"size"];
(二). Decay 衰減動畫
POPDecayAnimation *anim = [POPDecayAnimation animationWithPropertyNamed:kPOPLayerPositionX];
anim.velocity = [NSValue valueWithCGPoint:CGPointMake(3,3)]; // 速度
[layer pop_addAnimation:anim forKey:@"slide"];
(三). Basic 基礎(chǔ)動畫
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 自定義動畫
// 占位
二. 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 動畫開始
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; // 彈簧彈力:晃動的幅度,[0-20, 默認為4]
springAnimation.springSpeed = 3; // 彈簧速度 [0-20,默認為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, kPOPViewSizerLayer: 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"];