进入本文章,相信大家都知道,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”];
步骤1选择种类的动画
POPBasicAnimation
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionLinear];
//kCAMediaTimingFunctionLinear kCAMediaTimingFunctionEaseIn kCAMediaTimingFunctionEaseOut kCAMediaTimingFunctionEaseInEaseOut
POPSpringAnimation
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
POPDecayAnimation * decayAnimation = [POPDecayAnimationanimation];decayAnimation.velocity = @(233);
//每秒值单位变化decayAnimation.deceleration =。833;//范围0到1
例子
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];
步骤2决定是否对视图属性或图层属性进行动画处理
查看属性
Alpha-kPOPViewAlpha
颜色 - kPOPViewBackgroundColor
大小 - kPOPViewBounds
中心 - kPOPViewCenter
位置和大小 - kPOPViewFrame
大小 - kPOPViewScaleXY
大小(缩放) - kPOPViewSize
图层属性
颜色 - kPOPLayerBackgroundColor
大小 - kPOPLayerBounds
大小 - kPOPLayerScaleXY
大小 - kPOPLayerSize
不透明度 - kPOPLayerOpacity
位置 - kPOPLayerPosition
X位置 - kPOPLayerPositionX
Y位置 - kPOPLayerPositionY
旋转 - kPOPLayerRotation
颜色 - kPOPLayerBackgroundColor
例子
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];
注意:适用于任何Layer属性或从UIView继承的任何对象,如UIToolbar |UIPickerView |UIDatePicker |UIScrollView |UITextView |UIImageView |UITableViewCell |UIStepper |UIProgressView |UIActivityIndicatorView |UISwitch |UISlider |UITextField |UISegmentedControl |UIButton |UIView |UITableView
步骤3找到下面的属性,然后添加和设置.toValue
查看属性
Alpha-kPOPViewAlpha
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewAlpha];basicAnimation.toValue = @(0);
//scale from 0 to 1
颜色 - kPOPViewBackgroundColor
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewBackgroundColor];basicAnimation.toValue = [UIColorredColor];
大小 - kPOPViewBounds
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewBounds];basicAnimation.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0,90,190)];//前2个值不要
中心 - kPOPViewCenter
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewCenter];basicAnimation.toValue = [NSValuevalueWithCGPoint:CGPointMake(200,200)];
位置和大小 - kPOPViewFrame
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewFrame];basicAnimation.toValue = [NSValuevalueWithCGRect:CGRectMake(140,140,140,140)];
大小 - kPOPViewScaleXY
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewScaleXY];basicAnimation.toValue = [NSValuevalueWithCGSize:CGSizeMake(3,2)];
大小(缩放) - kPOPViewSize
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPViewSize];basicAnimation.toValue = [NSValuevalueWithCGSize:CGSizeMake(30,200)];
图层属性
颜色 - kPOPLayerBackgroundColor
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerBackgroundColor];basicAnimation.toValue = [UIColorredColor];
大小 - kPOPLayerBounds
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerBounds];basicAnimation.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0,90,90)];//前2个值不要
大小 - kPOPLayerScaleXY
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerScaleXY];basicAnimation.toValue = [NSValuevalueWithCGSize:CGSizeMake(2,1)];//增加宽度和高度标度
大小 - kPOPLayerSize
POPBasicAnimation * basicAnimation = [POPBasicAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerSize];basicAnimation.toValue = [NSValuevalueWithCGSize:CGSizeMake(200,200)];
不透明度 - kPOPLayerOpacity
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerOpacity];basicAnimation.toValue = @(0);
位置 - kPOPLayerPosition
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerPosition];basicAnimation.toValue = [NSValuevalueWithCGRect:CGRectMake(130,130,0,0)];//last 2 values dont matter
X位置 - kPOPLayerPositionX
POPSpringAnimation * basicAnimation = [POPSpringAnimationanimation];basicAnimation.property = [POPAnimatablePropertypropertyWithName:kPOPLayerPositionX];basicAnimation.toValue = @(240);
Y位置 - kPOPLayerPositionY
POPSpringAnimation * anim = [POPSpringAnimationanimation];anim.property = [POPAnimatablePropertypropertyWithName:kPOPLayerPositionY];anim.toValue = @(320);
旋转 - kPOPLayerRotation
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是整个旋转
步骤4为动画创建名称和委派
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;
步骤5添加动画到查看
[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谢谢!