首页 > 代码库 > Facebook POP动画简单使用
Facebook POP动画简单使用
简单实用POP动画
发现POP比较好的一点是保留了动画结束后的状态,通过block回调。使用POPAnimatableProperty 可以快速添加基本动画,也可以自定义属性动画。
弹性动画
- (void)spring{
POPSpringAnimation* framePOP = [POPSpringAnimationanimationWithPropertyNamed:kPOPViewBackgroundColor];
framePOP.springSpeed =10.f;
framePOP.springBounciness =4.f;
framePOP.toValue = [UIColorgreenColor];
[framePOPsetCompletionBlock:^(POPAnimation * anim ,BOOL finsih) {
if (finsih) {
NSLog(@"view.frame = %@",NSStringFromCGRect(view.frame));
}
}];
[viewpop_addAnimation:framePOP forKey:@"go"];
}
减缓动画
- (void)Decay{
POPDecayAnimation* decay = [POPDecayAnimationanimationWithPropertyNamed:kPOPViewFrame];
// decay.toValue = http://www.mamicode.com/[NSValue valueWithCGRect:CGRectMake(200, 400, 100, 100)];
decay.velocity = [NSValuevalueWithCGRect:CGRectMake(200,300, 100, 100)];
[viewpop_addAnimation:decay forKey:@"go"];
}
基本动画
-(void)basic{
POPBasicAnimation* basicAnimation = [POPBasicAnimationanimationWithPropertyNamed:kPOPLayerCornerRadius];
basicAnimation.toValue = [NSNumbernumberWithFloat:CGRectGetHeight(view.frame)/2.];
basicAnimation.timingFunction =[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
// basicAnimation.duration = 3.f;
[basicAnimationsetCompletionBlock:^(POPAnimation * ani,BOOL fin) {
if (fin) {
NSLog(@"view.frame = %@",NSStringFromCGRect(view.frame));
// POPBasicAnimation* newBasic = [POPBasicAnimation easeInEaseOutAnimation];
// newBasic.property = [POPAnimatableProperty propertyWithName:kPOPLayerCornerRadius];
// newBasic.toValue = http://www.mamicode.com/[NSNumber numberWithFloat:0];
// [view.layer pop_addAnimation:newBasic forKey:@"go"];
}
}];
[view.layerpop_addAnimation:basicAnimation forKey:@"frameChange"];
}
组合动画
-(void)group
{
view.transform =CGAffineTransformMakeRotation(M_PI_2/3);
POPBasicAnimation* spring = [POPBasicAnimationanimationWithPropertyNamed:kPOPLayerPositionY];
spring.beginTime =CACurrentMediaTime();
spring.duration =.4f;
spring.fromValue = [NSNumbernumberWithFloat:-100.f];
spring.toValue = [NSNumbernumberWithFloat:CGRectGetMinY(view.frame) +80];
[springsetCompletionBlock:^(POPAnimation * ani,BOOL fin) {
}];
POPBasicAnimation* basic = [POPBasicAnimationanimationWithPropertyNamed:kPOPLayerRotation];
basic.beginTime =CACurrentMediaTime();
basic.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
basic.toValue = [NSNumbernumberWithFloat:-M_PI_4];
basic.duration =.4f;
POPBasicAnimation* rotation = [POPBasicAnimationanimationWithPropertyNamed:kPOPLayerRotation];
rotation.beginTime =CACurrentMediaTime() + .4f;
rotation.toValue = [NSNumbernumberWithFloat:0.f];
rotation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
rotation.duration =.25f;
POPBasicAnimation* donw = [POPBasicAnimationanimationWithPropertyNamed:kPOPLayerPositionY];
donw.beginTime =CACurrentMediaTime() + 0.4f;
donw.toValue = [NSNumbernumberWithFloat:CGRectGetMinY(view.frame)];
donw.duration =.25f;
donw.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[view.layerpop_addAnimation:spring forKey:@"spring"];
[view.layerpop_addAnimation:basic forKey:@"basic"];
[view.layerpop_addAnimation:donw forKey:@"down"];
[view.layerpop_addAnimation:rotation forKey:@"rotation"];
}
Facebook POP动画简单使用