iOS开发

我的POP动画学习之路

2017-08-22  本文已影响76人  楚雄天下

作为一个菜鸟,在我刚进入ios这个坑的时候,动画对我来说好像很高大上,很遥远,但是事实却是真的很高大上很遥远,为了纪念我的动画学习之路,特书此文,以表......

一、导入POP框架

1.CocoaPods方法导入 

直接 pod ‘pop’ 或者 pod 'pop',:git => 'https://github.com/facebook/pop.git'

2.没有CocoaPods导入方法 首先下载POP这个框架,可在这https://github.com/facebook/pop 下载,下载完之后添加到你的工程里。注意,记得把工程的Other Linker Flags 选项添加 “-lc++”;(如图POP1所示)

POP1

二、POP的使用在这里只列举少部分例子 

1.第一步是导入头文件 #import遵循协议

例子1:弹性扩张动画

首先创建一个动画动作的View

self.popView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

self.popView.center = self.view.center;

self.popView.backgroundColor = [UIColor greenColor];

self.popView.layer.cornerRadius = self.popView.frame.size.width *0.5;

[self.view addSubview:self.popView];

然后就是创建弹性动画,代码如下

POPSpringAnimation * springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewScaleXY];

springAnimation.name = @"222222";

springAnimation.delegate = self;

springAnimation.toValue            = [NSValue valueWithCGPoint:CGPointMake(1, 1)];

springAnimation.velocity            = [NSValue valueWithCGPoint:CGPointMake(-2, -2)];

springAnimation.springBounciness    = 20.f;

springAnimation.springSpeed        = 10.f;

springAnimation.dynamicsTension    = 700.f;//动态张力

springAnimation.dynamicsFriction    = 7.f;//摩擦

springAnimation.dynamicsMass        = 3.f;//动态质量

[self.popView pop_addAnimation:springAnimation forKey:nil];

监听动画结束可以实现其协议方法里的

-(void)pop_animationDidStop:(POPAnimation *)anim finished:(BOOL)finished方法

例子2:旋转动画

POPSpringAnimation *spin = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerRotation];

spin.fromValue = @(M_PI / 4);

spin.toValue = @(0);

spin.springBounciness = 20;

spin.velocity = @(10);

[self.popView.layer pop_addAnimation:spin forKey:@"likeAnimation"];

例子3:膨胀

POPSpringAnimation *sprintAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewScaleXY];

sprintAnimation.velocity = [NSValue valueWithCGPoint:CGPointMake(8, 8)];

sprintAnimation.springBounciness = 20.f;

sprintAnimation.name = @"1233";

//    sprintAnimation.delegate = self;

[bt pop_addAnimation:sprintAnimation forKey:@"sendAnimation"];

注意:有没有发现,其实这几个动画除了参数不一样外,最大的区别就是animationWithPropertyNamed:这里这个Name不一样,所以决定不同动画就用不同的Name,其它参数就可以按自己的需求实际来设计了

例子一:UITableViewCell 动画

要在UITableViewCell 上添加动画,其实也不难,效果就是当我们点击某一个cell的时候,动画就开始,在这个例子中,我们给cell添加两个动画,一个是放大与缩回动画。

要重写UITableViewCell的-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated方法,在该方法中添加代码如下:

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated

{

[super setHighlighted:highlighted animated:animated];

if (self.highlighted) {

POPBasicAnimation *scaleAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewScaleXY];

scaleAnimation.duration = 0.1;

scaleAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(1, 1)];

[self.textLabel pop_addAnimation:scaleAnimation forKey:@"scalingUp"];

} else {

POPSpringAnimation *sprintAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewScaleXY];

sprintAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(0.9, 0.9)];

sprintAnimation.velocity = [NSValue valueWithCGPoint:CGPointMake(2, 2)];

sprintAnimation.springBounciness = 50.f;

[self.textLabel pop_addAnimation:sprintAnimation forKey:@"springAnimation"];

}

}

如此即可实现cell动画,动画效果如下图POP2(这个动画效果图是网上盗用的:http://www.jianshu.com/p/47ce70f3bf59)

POP2

总结:说了那么多,是时候该来总结一下了,POP 动画的简单应用方法都是大同小异,主要是区分 animationWithPropertyNamed:这个方法,现在总结一下这个方法的种类:

/*

/**

图层(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;

/**

图形层(CAShapeLayer)通用动画属性.

extern NSString * const kPOPShapeLayerStrokeStart;

extern NSString * const kPOPShapeLayerStrokeEnd;

extern NSString * const kPOPShapeLayerStrokeColor;

extern NSString * const kPOPShapeLayerFillColor;

/**

视图约束(NSLayoutConstraint)通用动画属性.

extern NSString * const kPOPLayoutConstraintConstant;

/**

视图(UIView)通用动画属性.

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;

/**

滚动视图(UIScrollView)通用动画属性.

extern NSString * const kPOPScrollViewContentOffset;

extern NSString * const kPOPScrollViewContentSize;

extern NSString * const kPOPScrollViewZoomScale;

extern NSString * const kPOPScrollViewContentInset;

/**

列表(UITableView)通用动画属性.

extern NSString * const kPOPTableViewContentOffset;

extern NSString * const kPOPTableViewContentSize;

/**

集合视图(UICollectionView)通用动画属性.

extern NSString * const kPOPCollectionViewContentOffset;

extern NSString * const kPOPCollectionViewContentSize;

/**

导航栏(UINavigationBar)通用动画属性.

extern NSString * const kPOPNavigationBarBarTintColor;

/**

工具栏(UIToolBar)通用动画属性.

extern NSString * const kPOPToolbarBarTintColor;

/**

标签栏(UITabBar)通用动画属性.

extern NSString * const kPOPTabBarBarTintColor;

/**

标签(UILabel)通用动画属性.

extern NSString * const kPOPLabelTextColor;

*/

时间问题,先写到这,以后接着写转场动画等例子。。。。。。

———————— 蒋

上一篇 下一篇

猜你喜欢

热点阅读