POP动画[1]

pop动画是facebook扩展CoreAnimation的,使用及其方便:)

1:Spring系列的弹簧效果(两个动画kPOPLayerBounds与kPOPLayerCornerRadius同时运行)

#import "RootViewController.h"
#import "YXEasing.h"
#import "POP.h"
#import "YXGCD.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; // 初始化View
UIView *showView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
showView.center = self.view.center;
showView.layer.cornerRadius = ;
showView.backgroundColor = [UIColor cyanColor];
[self.view addSubview:showView]; // 延时7s后执行的代码
[[GCDQueue mainQueue] execute:^{ // 尺寸
POPSpringAnimation *bounds = \
[POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds]; // 圆角
POPSpringAnimation *cornerRadius = \
[POPSpringAnimation animationWithPropertyNamed:kPOPLayerCornerRadius]; bounds.toValue = [NSValue valueWithCGRect:CGRectMake(, , , )];
bounds.springSpeed = ; cornerRadius.toValue = @();
cornerRadius.springSpeed = ; // 添加动画
[showView.layer pop_addAnimation:bounds
forKey:@"size"];
[showView.layer pop_addAnimation:cornerRadius
forKey:@"cornerRadius"]; } afterDelay:NSEC_PER_SEC * ];
} @end

2:一个动画结束后开始另外一个动画

//
// RootViewController.m
// Animation
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h"
#import "YXEasing.h"
#import "POP.h"
#import "YXGCD.h" @interface RootViewController ()<POPAnimationDelegate> @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; // 初始化View
UIView *showView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
showView.center = self.view.center;
showView.layer.cornerRadius = ;
showView.backgroundColor = [UIColor cyanColor];
[self.view addSubview:showView]; // 延时7s后执行的代码
[[GCDQueue mainQueue] execute:^{ // 位置
POPSpringAnimation *position = \
[POPSpringAnimation animationWithPropertyNamed:kPOPLayerPosition]; // 设置速度
position.springSpeed = .f; // 赋值
position.toValue = [NSValue valueWithCGPoint:CGPointMake(, )]; // 添加动画
[showView.layer pop_addAnimation:position forKey:nil]; // 结束后
[position setCompletionBlock:^(POPAnimation *animation, BOOL finished) {
// 颜色
POPSpringAnimation *backgroundColor = \
[POPSpringAnimation animationWithPropertyNamed:kPOPLayerBackgroundColor]; // 速度
backgroundColor.springSpeed = .f; // 赋值
backgroundColor.toValue = (id)[UIColor redColor].CGColor; // 添加动画
[showView.layer pop_addAnimation:backgroundColor forKey:nil];
}];
} afterDelay:NSEC_PER_SEC * ];
} @end

注意动画类型的不同导致toValue的值也不一样,这个始于CALayer的动画保持一致的:

3:动画中的代理

//
// RootViewController.m
// Animation
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h"
#import "YXEasing.h"
#import "POP.h"
#import "YXGCD.h" @interface RootViewController ()<POPAnimationDelegate> @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; // 初始化View
UIView *showView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
showView.center = self.view.center;
showView.layer.cornerRadius = ;
showView.backgroundColor = [UIColor cyanColor];
[self.view addSubview:showView]; // 延时7s后执行的代码
[[GCDQueue mainQueue] execute:^{ // 尺寸
POPSpringAnimation *bounds = \
[POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds]; // 设置代理
bounds.delegate = self; bounds.toValue = [NSValue valueWithCGRect:CGRectMake(, , , )];
bounds.springSpeed = ; // 添加动画
[showView.layer pop_addAnimation:bounds
forKey:@"size"]; } afterDelay:NSEC_PER_SEC * ];
} // 动画开始
- (void)pop_animationDidStart:(POPAnimation *)anim
{
NSLog(@"pop_animationDidStart %@", anim);
} // 动画值动态改变
- (void)pop_animationDidApply:(POPAnimation *)anim
{
NSLog(@"pop_animationDidApply %@", anim);
} // 动画到达终点值
- (void)pop_animationDidReachToValue:(POPAnimation *)anim
{
NSLog(@"pop_animationDidReachToValue %@", anim);
} // 动画结束
- (void)pop_animationDidStop:(POPAnimation *)anim finished:(BOOL)finished
{
NSLog(@"pop_animationDidStop %@", anim);
} @end

动画代理方法能够完整的表示出这个动画执行的过程,从开始到结束到中间值的改变我们都能获取到的.

4:按钮的动画效果

//
// RootViewController.m
// Animation
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h"
#import "YXEasing.h"
#import "POP.h"
#import "YXGCD.h" @interface RootViewController ()<POPAnimationDelegate> @property (nonatomic, strong) UIButton *button; @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; // 完整显示按住按钮后的动画效果
_button = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
_button.layer.cornerRadius = .f;
_button.backgroundColor = [UIColor cyanColor];
_button.center = self.view.center;
[self.view addSubview:_button]; // 按住按钮后没有松手的动画
[_button addTarget:self
action:@selector(scaleToSmall)
forControlEvents:UIControlEventTouchDown | UIControlEventTouchDragEnter]; // 按住按钮松手后的动画
[_button addTarget:self
action:@selector(scaleAnimation)
forControlEvents:UIControlEventTouchUpInside]; // 按住按钮后拖拽出去的动画
[_button addTarget:self
action:@selector(scaleToDefault)
forControlEvents:UIControlEventTouchDragExit];
} - (void)scaleToSmall
{
NSLog(@"scaleToSmall"); POPBasicAnimation *scaleAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerScaleXY];
scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(0.75f, 0.75f)];
[_button.layer pop_addAnimation:scaleAnimation forKey:@"layerScaleSmallAnimation"];
} - (void)scaleAnimation
{
NSLog(@"scaleAnimation"); POPSpringAnimation *scaleAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY];
scaleAnimation.velocity = [NSValue valueWithCGSize:CGSizeMake(.f, .f)];
scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(.f, .f)];
scaleAnimation.springBounciness = 18.0f;
[_button.layer pop_addAnimation:scaleAnimation forKey:@"layerScaleSpringAnimation"];
} - (void)scaleToDefault
{
NSLog(@"scaleToDefault"); POPBasicAnimation *scaleAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerScaleXY];
scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(.f, .f)];
[_button.layer pop_addAnimation:scaleAnimation forKey:@"layerScaleDefaultAnimation"];
} @end

POP的动画真心强大呢:)

5:Stroke动画效果

//
// RootViewController.m
// Animation
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h"
#import "YXEasing.h"
#import "POP.h"
#import "YXGCD.h"
#import "CAShapeLayer+Circle.h" @interface RootViewController ()<POPAnimationDelegate> @property (nonatomic, strong) GCDTimer *timer; @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; // 圆
CAShapeLayer *layer = [CAShapeLayer LayerWithCircleCenter:self.view.center
radius:.f
startAngle:DEGREES()
endAngle:DEGREES( + )
clockwise:YES
lineDashPattern:nil]; layer.strokeColor = [UIColor cyanColor].CGColor; // 边缘线的颜色
layer.lineCap = kCALineCapRound; // 边缘线的类型
layer.lineWidth = 5.0f; // 线条宽度
layer.strokeStart = 0.0f;
layer.strokeEnd = 1.0f; [self.view.layer addSublayer:layer]; _timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]];
[_timer event:^{ CGFloat value1 = arc4random()%/.f;
CGFloat value2 = arc4random()%/.f; POPSpringAnimation *strokeAnimationEnd = \
[POPSpringAnimation animationWithPropertyNamed:kPOPShapeLayerStrokeEnd];
strokeAnimationEnd.toValue = @(value1 > value2 ? value1 : value2);
strokeAnimationEnd.springBounciness = .f; POPSpringAnimation *strokeAnimationStart = \
[POPSpringAnimation animationWithPropertyNamed:kPOPShapeLayerStrokeStart];
strokeAnimationStart.toValue = @(value1 < value2 ? value1 : value2);
strokeAnimationStart.springBounciness = .f; [layer pop_addAnimation:strokeAnimationEnd forKey:@"layerStrokeAnimation"];
[layer pop_addAnimation:strokeAnimationStart forKey:@"layerStrokeAnimation1"]; } timeInterval:*NSEC_PER_SEC];
[_timer start];
} @end

6:减速动画

//
// RootViewController.m
// Animation
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h"
#import "YXEasing.h"
#import "POP.h"
#import "YXGCD.h" @interface RootViewController ()<POPAnimationDelegate> @property(nonatomic) UIControl *dragView; @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; UIPanGestureRecognizer *recognizer = \
[[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(handlePan:)]; self.dragView = [[UIControl alloc] initWithFrame:CGRectMake(, , , )];
self.dragView.center = self.view.center;
self.dragView.layer.cornerRadius = CGRectGetWidth(self.dragView.bounds)/;
self.dragView.backgroundColor = [UIColor cyanColor];
[self.dragView addGestureRecognizer:recognizer]; // 当触目的时候移除动画
[self.dragView addTarget:self
action:@selector(touchDown:)
forControlEvents:UIControlEventTouchDown]; [self.view addSubview:self.dragView];
} - (void)touchDown:(UIControl *)sender
{
[sender.layer pop_removeAllAnimations];
} - (void)handlePan:(UIPanGestureRecognizer *)recognizer
{
// 拖拽
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(, ) inView:self.view];
NSLog(@"center %@", NSStringFromCGPoint(recognizer.view.center)); // 拖拽动作结束
if(recognizer.state == UIGestureRecognizerStateEnded)
{
// 计算出移动的速度
CGPoint velocity = [recognizer velocityInView:self.view];
NSLog(@"velocity %@", NSStringFromCGPoint(velocity)); // 衰退减速动画
POPDecayAnimation *positionAnimation = \
[POPDecayAnimation animationWithPropertyNamed:kPOPLayerPosition]; // 设置代理
positionAnimation.delegate = self; // 设置速度动画
positionAnimation.velocity = [NSValue valueWithCGPoint:velocity]; // 添加动画
[recognizer.view.layer pop_addAnimation:positionAnimation
forKey:@"layerPositionAnimation"];
}
} @end

计算出pan手势的在拖拽结束的时候的速度值.

POP动画[1]的更多相关文章

  1. iOS动画——弹窗动画(pop动画)

    用pop动画简单实现弹窗的缩放和渐变,感觉这个动画常用,就写一下博客 pop动画是Facebook推出的动画引擎,请自行到GitHub上搜索下载拖拽导入xcode项目中. 更多pop动画使用和原理可网 ...

  2. 用POP动画引擎实现衰减动画(POPDecayAnimation)

    效果图: #import "ViewController.h" #import <POP.h> @interface ViewController () @end @i ...

  3. POP动画引擎中Layer与CALayer的一点区别

    POP动画引擎是facebook提供的一个开源框架, 可以实现很多的动画效果, 这里就不一一介绍啦, 有兴趣的童鞋请移步: https://github.com/facebook/pop 下面简单的讲 ...

  4. 用POP动画编写带富文本的自定义动画效果

    用POP动画编写带富文本的自定义动画效果 [源码] https://github.com/YouXianMing/UI-Component-Collection [效果] [特点] * 支持富文本 * ...

  5. 用POP动画模拟真实秒钟摆动效果

    用POP动画模拟真实秒钟摆动效果 静态图: 动画图: 此处用到了POP中的Spring系列动画,现提供源码如下: SecondClockView.h 与 SecondClockView.m // // ...

  6. POP动画[3]

    POP动画[3] 这一节主要讲解POP动画的自定义动画属性. POP动画中有一个参数,叫timingFunction,与CoreAnimation中的一个参数CAMediaTimingFunction ...

  7. POP动画[2]

    POP动画[2] 1:定制控制器间的转场动画. 源码有点多-_-!! // // RootViewController.h // Animation // // Copyright (c) 2014年 ...

  8. 自定义UINavigationController push和pop动画

    http://segmentfault.com/q/1010000000143983 默认的UINavigationController push和pop的默认动画都是左右滑动推出,我的应用要求这种界 ...

  9. 转 脸书pop动画的五个步骤

    http://blog.csdn.net/u013741809/article/details/38511741 5 Steps For Using Facebook Pop   // 1. Pick ...

随机推荐

  1. 【Guava】Optional接口来避免空指针错误

    null会带来很多问题,从开始有null开始有无数程序栽在null的手里,null的含义是不清晰的,检查null在大多数情况下是不得不做的,而我们又在很多时候忘记了对null做检查,在我们的产品真正投 ...

  2. Redis-集群 - 分片

    Redis是一个基于内存的数据库,其不仅读写速度快,每秒可以执行大约110000的写操作,81000的读取操作,而且其支持存储字符串,哈希结构,链表,集合丰富的数据类型.所以得到很多开发者的青睐.加之 ...

  3. Android多媒体之view,SurfaceView,GLSurfaceView

    1.相关概念 不用画布,直接在窗口上进行绘图叫做无缓冲绘图. 用了一个画布,将所有内容都先画到画布上,在整体绘制到窗口上,就该叫做单缓冲绘图, 那个画布就是一个缓冲区.用了两个画布,一个进行临时的绘图 ...

  4. 关于Java 下 Snappy压缩存文件

    坑点: 压缩后的byte 数组中会有元素是负数,如果转化成String 存入文件,然后再读取解压缩还原,无法得到原来的结果,甚至是无法解压缩. 原因分析: String 底层是由char 数组构成的, ...

  5. python-poll实现异步IO

    #!usr/bin/python from socket import * from select import * from time import ctime s=socket() s.bind( ...

  6. python-Event事件线程同步和互斥

    #!/usr/bin/python #coding=utf-8 #用于线程间通信,通过事件标识控制 import threading from time import sleep,ctime def ...

  7. C#控件的Resize事件

    1. 当控件大小发生改变时,就会触发该事件 所以适合动态调整UI的布局, 例如: 国际化,不同语言导致控件长度不同: 控件的内容是动态增加的,也可以使用. 2.必须是大小会发生改变的控件才会触发该事件 ...

  8. PTA (Advanced Level) 1018 Public Bike Management

    Public Bike Management There is a public bike service in Hangzhou City which provides great convenie ...

  9. js禁止微信浏览器下拉显示黑底查看网址,不影响内部Scroll

    开发项目跑在微信浏览器经常会遇到一个问题,微信浏览器下拉的时候会出现自带的黑色底色(显示网址)如下图: 网上好多js禁止操作的做法禁止了内部Scroll,导致页面不能滚动,上拉加载失效,例如这种做法: ...

  10. IOS折线图

    做项目要统计商品的销售情况,美工那边给了效果图,自己就按照效果图自定义了一个ScrollView.整体效果不错,在做的过程中遇到的问题也记录一下. 现在这个还有许多优化的地方: 1.一个表中只能画一个 ...