走进 Facebook POP 的世界
?
?
POP: 一個流行的可擴展的動畫引擎iOS,它支持spring和衰變動態動畫,使其可用于構建現實,基于物理交互。Objective - C API允許快速集成, 對于所有的動畫和過渡他是成熟的.
?
解釋:
1.1 POP 使用 Objective-C++ 編寫,Objective-C++ 是對 C++ 的擴展,就像 Objective-C 是 C 的擴展。而至于為什么他們用 Objective-C++ 而不是純粹的 Objective-C. 可能是偏愛。-.O
1.2 POP 目前由四部分組成:1. Animations;2. Engine;3. Utility;4. WebCore。下圖有助于你更好的理解它的架構
?
?
1.它支持CocoaPods 你可以這樣
?
pod 'pop', '~> 1.0.8'
?
2.或者這樣點擊下載拉入工程 https://github.com/facebook/pop
?
3.我使用的Cocoapods 所以使用之前你需要這樣
?
#import <POP.h>
?
動圖
?
E1:
?
- (void)clickPopAction
{
????// kPOPLayerPositionY 向下
????// kPOPLayerPositionX 向右
????POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY];
????// 移動距離
????anim.toValue = [[NSNumber alloc] initWithFloat:_btnPop.center.y + 200];
????// 從當前 + 1s后開始
????anim.beginTime = CACurrentMediaTime() + 1.0f;
????// 彈力--晃動的幅度 (springSpeed速度)
????anim.springBounciness = 15.0f;
????[_btnPop pop_addAnimation:anim forKey:@"position"];
????POPSpringAnimation *anim1 = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
????anim1.toValue = [NSValue valueWithCGRect:CGRectMake(100, 100, 99, 99)];
????[_btnPop pop_addAnimation:anim1 forKey:@"size"];
}
?
動圖
?
E2:在很多金融類app中比較常見、支付寶中的余額包、京東金融余額、就類似這樣
?
// 初始化
????POPBasicAnimation *anim = [POPBasicAnimation animation];
????// 限時 1s
????anim.duration = 3.0;
????POPAnimatableProperty * prop = [POPAnimatableProperty propertyWithName:@"count++" initializer:^(POPMutableAnimatableProperty *prop) {
????????prop.readBlock = ^(id obj, CGFloat values[]){ values[0] = [[obj description] floatValue]; };
????????prop.writeBlock = ^(id obj, const CGFloat values[])
????????{
????????????[obj setText:[NSString stringWithFormat:@"%.2f",values[0]]];
????????};
????????prop.threshold = 0.01;
????}];
?
????anim.property = prop;
????anim.fromValue = @(0.0);
????anim.toValue = @(1314.52);
????[self.xt_countLabel pop_addAnimation:anim forKey:@"counting"];
?
動圖
?
E3
?
CALayer *layer0 = [CALayer layer];
????layer0.opacity = 1.0;
????layer0.transform = CATransform3DIdentity;
????[layer0 setMasksToBounds:YES];
????[layer0 setBackgroundColor:[UIColor colorWithRed:0.5448 green:0.6836 blue:0.9986 alpha:1.0].CGColor];
????[layer0 setCornerRadius:12.5];
????[layer0 setBounds:CGRectMake(0, 0, 25, 25)];
????[self.view.layer addSublayer:layer0];
????layer0.position = CGPointMake(self.view.center.x, 266);
????[self performAnimation:layer0];
?
- (void)performAnimation:(CALayer *)layer
{
????[layer pop_removeAllAnimations];
????POPBasicAnimation *anim = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerScaleXY];
????static BOOL ani = YES;
????if (ani) {
????????anim.toValue = [NSValue valueWithCGPoint:CGPointMake(1.0, 1.0)];
????}else{
????????anim.toValue = [NSValue valueWithCGPoint:CGPointMake(1.5, 1.5)];
????}
????ani = !ani;
????anim.completionBlock = ^(POPAnimation *anim, BOOL finished) {
????????if (finished) { [self performAnimation:layer]; }
????};
????[layer pop_addAnimation:anim forKey:@"Animation"];
}
轉載于:https://www.cnblogs.com/fengmin/p/5599531.html
總結
以上是生活随笔為你收集整理的走进 Facebook POP 的世界的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第十五周工作总结
- 下一篇: es6-let 和 const