facebook pop学习笔记-1

本文深入探讨了iOS开发中流行的动画技术,包括基本动画、弹簧动画、衰减动画等,介绍了它们的工作原理和使用方法,同时展示了如何通过自定义动画实现更复杂的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

pop 地址https://github.com/facebook/pop
有四种动画
1. 三种动画都继承自POPPropertyAnimation, POPPropertyAnimation继承自POPAnimation
     POPBasicAnimation 固定时间间隔的动画(如淡入淡出效果)
     POPSpringAnimation 类似弹簧一般的效果
     POPDecayAnimation 过阻尼效果
2. 自定义动画继承自POPAnimation
     POPCustomAnimation


3. timing function names
kCAMediaTimingFunctionLinear //linear 直线的
kCAMediaTimingFunctionEaseIn //渐入
kCAMediaTimingFunctionEaseOut //渐出
kCAMediaTimingFunctionEaseInEaseOut //渐入渐出
kCAMediaTimingFunctionDefault //默认


4. 添加一个动画步骤
a. 定义一个animation对象, 并指定对应的动画属性
b. 设置初始值和默认值(初始值可以不指定 会默认从当前值开始)
c. 添加到想产生动画的对象上


###1### POPAnimation.h
POPAnimation继承自NSObject
1. 属性:
NSString *name //动画名字
CFTimeInterval beginTime //the beginTime of the animation in media time默认0并且马上开始
id delegate //动画代理
POPAnimationTracer *tracer //动画追踪装置
void (^animationDidStartBlock)(POPAnimation *anim) //动画开始回调block
void (^animationDidReachToValueBlock)(POPAnimation *anim); //到达或超过toValue回调block
void (^completionBlock)(POPAnimation *anim, BOOL finished); //可选的,动画完成回调block
void (^animationDidApplyBlock)(POPAnimation *anim); //可选的,called each frame animation is applied.
BOOL removedOnCompletion; //动画完成是否移除
BOOL paused; //动画是否暂停
BOOL autoreverses //动画是否自动返回(倒着来一遍)
NSInteger repeatCount //动画重复次数
BOOL repeatForever //动画是否一直重复


2. POPAnimationDelegate协议
方法:
- (void)pop_animationDidStart:(POPAnimation *)anim; //动画开始
- (void)pop_animationDidReachToValue:(POPAnimation *)anim; //动画到达toValue
- (void)pop_animationDidStop:(POPAnimation *)anim finished:(BOOL)finished; //动画停止
- (void)pop_animationDidApply:(POPAnimation *)anim; //动画apply


3. 类目NSObject (POP)
方法:
- (void)pop_addAnimation:(POPAnimation *)anim forKey:(NSString *)key; //添加动画
- (void)pop_removeAllAnimations; //移除动画
- (void)pop_removeAnimationForKey:(NSString *)key; //移除动画
- (NSArray *)pop_animationKeys; //返回所有动画
- (id)pop_animationForKey:(NSString *)key; //reture any animation attached to the receiver. //@returns The animation currently attached , or nil if no such animation exists.


4. 类目POPAnimation (NSCopying) <NSCopying>


###2### POPPropertyAnimation.h
POPPropertyAnimation 继承自POPAnimation
1. 枚举POPAnimationClampFlags //clamp 夹住、上锁
  kPOPAnimationClampNone        = 0,
  kPOPAnimationClampStart       = 1UL << 0,
  kPOPAnimationClampEnd         = 1UL << 1,
  kPOPAnimationClampBoth = kPOPAnimationClampStart | kPOPAnimationClampEnd,
动画的值可以被约束在范围内。kPOPAnimationClampStart确保值大于fromValue, kPOPAnimationClampEnd确保值小于toValue


2. 属性:
POPAnimatableProperty *property //the property to animation //property财产
id fromValue //动画开始值
id toValue //动画到达值
CGFloat roundingFactor //the rounding factor applied to the current animated value //round 大约 factor 因素 applied 应用的 //specify 1.0 to animation between integral values. Defaults to 0 meaning no rounding //integral 必须的
NSUInteger clampMode //
BOOL additive //values是否应该added到每一个frame,而不是set


###3### POPCustomAnimation.h
POPCustomAnimation 继承自POPAnimation
1. typedef BOOL (^POPCustomAnimationBlock)(id target, POPCustomAnimation *animation);


2. 方法
+ (instancetype)animationWithBlock:(POPCustomAnimationBlock)block;


3. 属性
CFTimeInterval currentTime //The current animation time at time of callback.
CFTimeInterval elapsedTime //The elapsed animation time since last callback.


###4### POPBasicAnimation.h
POPBasicAnimation 继承自POPPropertyAnimation
1. 方法
+ (instancetype)animation;
+ (instancetype)animationWithPropertyNamed:(NSString *)name;
+ (instancetype)defaultAnimation; //Returns a basic animation with kCAMediaTimingFunctionDefault timing function.
+ (instancetype)linearAnimation; //Returns a basic animation with kCAMediaTimingFunctionLinear timing function.
+ (instancetype)easeInAnimation; //Returns a basic animation with kCAMediaTimingFunctionEaseIn timing function
+ (instancetype)easeOutAnimation; // Returns a basic animation with kCAMediaTimingFunctionEaseOut timing function.
+ (instancetype)easeInEaseOutAnimation; //Returns a basic animation with kCAMediaTimingFunctionEaseInEaseOut timing function


2. 属性
CFTimeInterval duration; //动画间隔 默认0.4
CAMediaTimingFunction *timingFunction; //A timing function defining the pacing of the animation. Defaults to nil indicating pacing according to kCAMediaTimingFunctionDefault


###5### POPSpringAnimation.h
POPSpringAnimation 继承自POPPropertyAnimation
1. 方法
+ (instancetype)animation;
+ (instancetype)animationWithPropertyNamed:(NSString *)name;
2. 属性
id velocity; //当前的速度值 //velocity 速度 在动画开始之前设置就是初始速度
CGFloat springBounciness //弹力, 值越大震动幅度越大//Defined as a value in the range [0, 20]. Defaults to 4.
CGFloat springSpeed //The effective speed//和springBounciness结合使用以改变动画effect // Defined as a value in the range [0, 20]. Defaults to 12.
CGFloat dynamicsTension //tension张力 //dynamics力学的
CGFloat dynamicsFriction //Friction摩擦力
CGFloat dynamicsMass //质量、体积


###6### POPDecayAnimation.h
POPDecayAnimation 继承自POPPropertyAnimation
1. 方法
+ (instancetype)animation;
+ (instancetype)animationWithPropertyNamed:(NSString *)name;
- (void)setToValue:(id)toValue NS_UNAVAILABLE; //the to value is derived based on input velocity and deceleration.
- (id)reversedVelocity; //the reversed velocity


2. 属性
id velocity;
id originalVelocity
CGFloat deceleration //衰减系数 deceleration减速 范围是[0,1],值越低表示减速越急
CFTimeInterval duration; // 预计的动画间隔 based on input velocity and deceleration values


###7### POPAnimatableProperty.h
1. POPAnimatableProperty 继承自NSObject 
+ (id)propertyWithName:(NSString *)name;
+ (id)propertyWithName:(NSString *)name initializer:(void (^)(POPMutableAnimatableProperty *prop))block;
@property (readonly, nonatomic, copy) NSString *name;
@property (readonly, nonatomic, copy) void (^readBlock)(id obj, CGFloat values[]);
@property (readonly, nonatomic, copy) void (^writeBlock)(id obj, const CGFloat values[]);
@property (readonly, nonatomic, assign) CGFloat threshold;


2. POPMutableAnimatableProperty 
@property (readwrite, nonatomic, copy) NSString *name;
@property (readwrite, nonatomic, copy) void (^readBlock)(id obj, CGFloat values[]);
@property (readwrite, nonatomic, copy) void (^writeBlock)(id obj, const CGFloat values[]);
@property (readwrite, nonatomic, assign) CGFloat threshold;


3. CALayer 所有支持的属性
extern NSString * const kPOPLayerBackgroundColor;
extern NSString * const kPOPLayerBounds;
extern NSString * const kPOPLayerCornerRadius;
extern NSString * const kPOPLayerBorderWidth;
extern NSString * const kPOPLayerBorderColor;
extern NSString * const kPOPLayerOpacity;
extern NSString * const kPOPLayerPosition;
extern NSString * const kPOPLayerPositionX;
extern NSString * const kPOPLayerPositionY;
extern NSString * const kPOPLayerRotation;
extern NSString * const kPOPLayerRotationX;
extern NSString * const kPOPLayerRotationY;
extern NSString * const kPOPLayerScaleX;
extern NSString * const kPOPLayerScaleXY;
extern NSString * const kPOPLayerScaleY;
extern NSString * const kPOPLayerSize;
extern NSString * const kPOPLayerSubscaleXY;
extern NSString * const kPOPLayerSubtranslationX;
extern NSString * const kPOPLayerSubtranslationXY;
extern NSString * const kPOPLayerSubtranslationY;
extern NSString * const kPOPLayerSubtranslationZ;
extern NSString * const kPOPLayerTranslationX;
extern NSString * const kPOPLayerTranslationXY;
extern NSString * const kPOPLayerTranslationY;
extern NSString * const kPOPLayerTranslationZ;
extern NSString * const kPOPLayerZPosition;
extern NSString * const kPOPLayerShadowColor;
extern NSString * const kPOPLayerShadowOffset;
extern NSString * const kPOPLayerShadowOpacity;
extern NSString * const kPOPLayerShadowRadius;


/**
 Common CAShapeLayer property names.
 */
extern NSString * const kPOPShapeLayerStrokeStart;
extern NSString * const kPOPShapeLayerStrokeEnd;
extern NSString * const kPOPShapeLayerStrokeColor;
extern NSString * const kPOPShapeLayerFillColor;
extern NSString * const kPOPShapeLayerLineWidth;
extern NSString * const kPOPShapeLayerLineDashPhase;


/**
 Common NSLayoutConstraint property names.
 */
extern NSString * const kPOPLayoutConstraintConstant;




#if TARGET_OS_IPHONE


/**
 Common UIView property names.
 */
extern NSString * const kPOPViewAlpha;
extern NSString * const kPOPViewBackgroundColor;
extern NSString * const kPOPViewBounds;
extern NSString * const kPOPViewCenter;
extern NSString * const kPOPViewFrame;
extern NSString * const kPOPViewScaleX;
extern NSString * const kPOPViewScaleXY;
extern NSString * const kPOPViewScaleY;
extern NSString * const kPOPViewSize;
extern NSString * const kPOPViewTintColor;


/**
 Common UIScrollView property names.
 */
extern NSString * const kPOPScrollViewContentOffset;
extern NSString * const kPOPScrollViewContentSize;
extern NSString * const kPOPScrollViewZoomScale;
extern NSString * const kPOPScrollViewContentInset;
extern NSString * const kPOPScrollViewScrollIndicatorInsets;


/**
 Common UITableView property names.
 */
extern NSString * const kPOPTableViewContentOffset;
extern NSString * const kPOPTableViewContentSize;


/**
 Common UICollectionView property names.
 */
extern NSString * const kPOPCollectionViewContentOffset;
extern NSString * const kPOPCollectionViewContentSize;


/**
 Common UINavigationBar property names.
 */
extern NSString * const kPOPNavigationBarBarTintColor;


/**
 Common UIToolbar property names.
 */
extern NSString * const kPOPToolbarBarTintColor;


/**
 Common UITabBar property names.
 */
extern NSString * const kPOPTabBarBarTintColor;


/**
 Common UILabel property names.
 */
extern NSString * const kPOPLabelTextColor;


#else


/**
 Common NSView property names.
 */
extern NSString * const kPOPViewFrame;
extern NSString * const kPOPViewBounds;
extern NSString * const kPOPViewAlphaValue;
extern NSString * const kPOPViewFrameRotation;
extern NSString * const kPOPViewFrameCenterRotation;
extern NSString * const kPOPViewBoundsRotation;


/**
 Common NSWindow property names.
 */
extern NSString * const kPOPWindowFrame;
extern NSString * const kPOPWindowAlphaValue;
extern NSString * const kPOPWindowBackgroundColor;


#endif


#if SCENEKIT_SDK_AVAILABLE


/**
 Common SceneKit property names.
 */
extern NSString * const kPOPSCNNodePosition;
extern NSString * const kPOPSCNNodePositionX;
extern NSString * const kPOPSCNNodePositionY;
extern NSString * const kPOPSCNNodePositionZ;
extern NSString * const kPOPSCNNodeTranslation;
extern NSString * const kPOPSCNNodeTranslationX;
extern NSString * const kPOPSCNNodeTranslationY;
extern NSString * const kPOPSCNNodeTranslationZ;
extern NSString * const kPOPSCNNodeRotation;
extern NSString * const kPOPSCNNodeRotationX;
extern NSString * const kPOPSCNNodeRotationY;
extern NSString * const kPOPSCNNodeRotationZ;
extern NSString * const kPOPSCNNodeRotationW;
extern NSString * const kPOPSCNNodeEulerAngles;
extern NSString * const kPOPSCNNodeEulerAnglesX;
extern NSString * const kPOPSCNNodeEulerAnglesY;
extern NSString * const kPOPSCNNodeEulerAnglesZ;
extern NSString * const kPOPSCNNodeOrientation;
extern NSString * const kPOPSCNNodeOrientationX;
extern NSString * const kPOPSCNNodeOrientationY;
extern NSString * const kPOPSCNNodeOrientationZ;
extern NSString * const kPOPSCNNodeOrientationW;
extern NSString * const kPOPSCNNodeScale;
extern NSString * const kPOPSCNNodeScaleX;
extern NSString * const kPOPSCNNodeScaleY;
extern NSString * const kPOPSCNNodeScaleZ;
extern NSString * const kPOPSCNNodeScaleXY;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值