进入本文章,相信大家都知道,iOS 动画 及 图形设计是iOS开发中的一大难点,本文主要讲解Fecebook 提供的 PoP 使用教程,提供PoP API 及 属性进行中文解释。以便大家更快的掌握 Fecebook PoP,不废话,马上进入话题,请往下看。
Pop是一个用于iOS,tvOS和OS X的可扩展的动画引擎。除了基本的静态动画,它支持弹簧和衰减动态动画,使它对建立真实的基于物理的交互有用。API允许快速集成现有的Objective-C代码库,并支持任何对象上的任何属性的动画。它是一个成熟和经过良好测试的框架,驱动纸张中的所有动画和过渡。
#5步骤使用Facebook PoP#
// 1.选择一种动画//
POPBasicAnimation POPSpringAnimation POPDecayAnimation
POPSpringAnimation * basicAnimation = [POPSpringAnimation animation];
// 2.决定天气,你会动画视图属性或图层特性,让我们选择一个视图属性并挑选kPOPViewFrame
//查看属性-
kPOPViewAlpha
kPOPViewBackgroundColor
kPOPViewBounds
kPOPViewCenter
kPOPViewFrame
kPOPViewScaleXY
kPOPViewSize
//图层属性-
kPOPLayerBackgroundColor
kPOPLayerBounds
kPOPLayerScaleXY
kPOPLayerSize
kPOPLayerOpacity
kPOPLayerPosition
kPOPLayerPositionX
kPOPLayerPositionY
kPOPLayerRotation
kPOPLayerBackgroundColorbasicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewFrame];
//3.计算出哪三种方法来设置toValue
//anim.toValue = @(1.0);
//anim.toValue = [NSValue valueWithCGRect:CGRectMake(0,0,400,400)];
//anim.toValue = [NSValue valueWithCGSize:CGSizeMake(40,40)];
//basicAnimation.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0,90,190)];
//4.为动画和设置代理创建名称basicAnimation.name =@“AnyAnimationNameYouWant”;basicAnimation.delegate = self
//5.添加动画到View或Layer,我们选择View so self.tableView而不是layer self.tableView.layer[self.tableViewpop_addAnimation:basicAnimationforKey:@“WhatEverNameYouWant”];
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionLinear];
//kCAMediaTimingFunctionLinear kCAMediaTimingFunctionEaseIn kCAMediaTimingFunctionEaseOut kCAMediaTimingFunctionEaseInEaseOut
POPSpringAnimation * springAnimation = [POPSpringAnimationanimation];springAnimation.velocity = @(1000);
//每秒值单位的变化springAnimation.springBounciness =14;
//value between 0-20 default at 4springAnimation.springSpeed =3;//value between 0-20 default at 4
POPDecayAnimation * decayAnimation = [POPDecayAnimationanimation];decayAnimation.velocity = @(233);
//每秒值单位变化decayAnimation.deceleration =。833;//范围0到1
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewAlpha];basicAnimation.toValue = @(0);
//scale from 0 to 1
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewBackgroundColor];basicAnimation.toValue = [UIColorredColor];
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewBounds];basicAnimation.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0,90,190)];//前2个值不要
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewCenter];basicAnimation.toValue = [NSValuevalueWithCGPoint:CGPointMake(200,200)];
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewFrame];basicAnimation.toValue = [NSValuevalueWithCGRect:CGRectMake(140,140,140,140)];
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewScaleXY];basicAnimation.toValue = [NSValuevalueWithCGSize:CGSizeMake(3,2)];
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewSize];basicAnimation.toValue = [NSValuevalueWithCGSize:CGSizeMake(30,200)];
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerBackgroundColor];basicAnimation.toValue = [UIColorredColor];
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerBounds];basicAnimation.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0,90,90)];//前2个值不要
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerScaleXY];basicAnimation.toValue = [NSValuevalueWithCGSize:CGSizeMake(2,1)];//增加宽度和高度标度
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerSize];basicAnimation.toValue = [NSValuevalueWithCGSize:CGSizeMake(200,200)];
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerOpacity];basicAnimation.toValue = @(0);
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerPosition];basicAnimation.toValue = [NSValuevalueWithCGRect:CGRectMake(130,130,0,0)];//last 2 values dont matter
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerPositionX];basicAnimation.toValue = @(240);
POPSpringAnimation * anim = [POPSpringAnimationanimation];anim.property = [POPAnimatablePropertypropertyWithName:kPOPLayerPositionY];anim.toValue = @(320);
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerRotation];basicAnimation.toValue = @(M_PI /4);//2 M_PI是整个旋转
注意:属性更改适用于所有3种动画类型 - POPBasicAnimation POPSpringAnimation POPDecayAnimation
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerRotation];basicAnimation.toValue = @(M_PI /4);//2 M_PI是整个旋转
basicAnimation.name =@“WhatEverAnimationNameYouWant”;basicAnimation.delegate = self;
- (void)pop_animationDidStart:(POPAnimation *)anim;
- (void)pop_animationDidStop:(POPAnimation *)anim finished :(BOOL)finished;
- (void)pop_animationDidReachToValue:(POPAnimation *)anim;
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewFrame];basicAnimation.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0,90,190)];basicAnimation.name =@“WhatEverAnimationNameYouWant”;basicAnimation.delegate = self;
[self.tableViewpop_addAnimation:basicAnimationforKey:@“WhatEverNameYouWant”];
例子
POPSpringAnimation * basicAnimation = [POPSpringAnimation animation];
basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewFrame];
basicAnimation.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0,90,190)];
basicAnimation.name =@“SomeAnimationNameYouChoose”;
basicAnimation.delegate = self;
[self.tableViewpop_addAnimation:basicAnimationforKey:@“WhatEverNameYouWant”];
结语:
PoP GitHub 地址:https://github.com/facebook/pop
本文章持续更新,更新至PoP框架里面的API及属性,以中文详解并以Demo形式更新。
看到这里, 你觉得可以请点下👍 你的赞是我持续更新的动力,O(∩_∩)O谢谢!
网友评论