Facebook发布了Paper之后,进一步开源了其背后的动画引擎Pop,此框架并不满足于苹果自身的动画单调性,致力于给用户一种逼真的动画效果,可以减少用户对于苹果原生Core Animation 复杂的运算,并且Pop提供的API和苹果原生的API用法类似,让开发者更容易接受。使用pop框架进行动画展示会让你的App看起来更加有生气,感觉像是活了一样。
它主要包含的动画:
POPSpringAnimation 有弹性效果的动画类
POPBasicAnimation基本动画
POPDecayAnimation衰减动画类
POPCustomAnimation可以自定义动画的类
个人使用第一种动画比较多,做了个小Demo,仅做参考。
@interface ViewController () @property (nonatomic,strong) UIButton *button; @property (nonatomic,assign) BOOL isSelected; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; [self.view addSubview:self.button ];
[self.button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
[self.button setBackgroundImage:[UIImage imageNamed:@"deleteButtonNormal"] forState:UIControlStateNormal];
self.button.backgroundColor = [UIColor orangeColor]; self.isSelected = YES;
} //懒加载
- (UIButton *)button{
if (_button == nil) {
_button = [[UIButton alloc]initWithFrame:CGRectMake(, , , )];
}
return _button;
} - (void)buttonClick{
POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerSize]; if (self.isSelected == YES) {
[_button setBackgroundImage:[UIImage imageNamed:@"deleteButtonSelected"] forState:UIControlStateNormal];
self.isSelected = NO;
springAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(, )];
}else{
[_button setBackgroundImage:[UIImage imageNamed:@"deleteButtonNormal"] forState:UIControlStateNormal];
self.isSelected = YES;
springAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(, )];
}
//弹性值
springAnimation.springBounciness = ;
//弹性速度
springAnimation.springSpeed = ; [self.button.layer pop_addAnimation:springAnimation forKey:@"changesize"];
}
这是一个很简单的展示,作为学习pop框架的开始。