POP动画[1]

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];// 初始化ViewUIView *showView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];showView.center  = self.view.center;showView.layer.cornerRadius = 25;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(0, 0, 200, 200)];bounds.springSpeed = 0;cornerRadius.toValue     = @(100);cornerRadius.springSpeed = 0;// 添加动画
        [showView.layer pop_addAnimation:boundsforKey:@"size"];[showView.layer pop_addAnimation:cornerRadiusforKey:@"cornerRadius"];} afterDelay:NSEC_PER_SEC * 7];
}@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];// 初始化ViewUIView *showView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];showView.center  = self.view.center;showView.layer.cornerRadius = 25;showView.backgroundColor = [UIColor cyanColor];[self.view addSubview:showView];// 延时7s后执行的代码[[GCDQueue mainQueue] execute:^{// 位置POPSpringAnimation *position = \[POPSpringAnimation animationWithPropertyNamed:kPOPLayerPosition];// 设置速度position.springSpeed = 0.f;// 赋值position.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 200)];// 添加动画
        [showView.layer pop_addAnimation:position forKey:nil];// 结束后[position setCompletionBlock:^(POPAnimation *animation, BOOL finished) {// 颜色POPSpringAnimation *backgroundColor = \[POPSpringAnimation animationWithPropertyNamed:kPOPLayerBackgroundColor];// 速度backgroundColor.springSpeed = 0.f;// 赋值backgroundColor.toValue = (id)[UIColor redColor].CGColor;// 添加动画
            [showView.layer pop_addAnimation:backgroundColor forKey:nil];}];} afterDelay:NSEC_PER_SEC * 7];
}@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];// 初始化ViewUIView *showView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];showView.center  = self.view.center;showView.layer.cornerRadius = 25;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(0, 0, 200, 200)];bounds.springSpeed = 0;// 添加动画
        [showView.layer pop_addAnimation:boundsforKey:@"size"];} afterDelay:NSEC_PER_SEC * 7];
}// 动画开始
- (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(0, 0, 70, 30)];_button.layer.cornerRadius = 5.f;_button.backgroundColor = [UIColor cyanColor];_button.center = self.view.center;[self.view addSubview:_button];// 按住按钮后没有松手的动画
    [_button addTarget:selfaction:@selector(scaleToSmall)forControlEvents:UIControlEventTouchDown | UIControlEventTouchDragEnter];// 按住按钮松手后的动画
    [_button addTarget:selfaction:@selector(scaleAnimation)forControlEvents:UIControlEventTouchUpInside];// 按住按钮后拖拽出去的动画
    [_button addTarget:selfaction:@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(3.f, 3.f)];scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(1.f, 1.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(1.f, 1.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.centerradius:50.fstartAngle:DEGREES(180)endAngle:DEGREES(180 + 360)clockwise:YESlineDashPattern: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()%100/100.f;CGFloat value2 = arc4random()%100/100.f;POPSpringAnimation *strokeAnimationEnd = \[POPSpringAnimation animationWithPropertyNamed:kPOPShapeLayerStrokeEnd];strokeAnimationEnd.toValue = @(value1 > value2 ? value1 : value2);strokeAnimationEnd.springBounciness = 12.f;POPSpringAnimation *strokeAnimationStart = \[POPSpringAnimation animationWithPropertyNamed:kPOPShapeLayerStrokeStart];strokeAnimationStart.toValue = @(value1 < value2 ? value1 : value2);strokeAnimationStart.springBounciness = 12.f;[layer pop_addAnimation:strokeAnimationEnd forKey:@"layerStrokeAnimation"];[layer pop_addAnimation:strokeAnimationStart forKey:@"layerStrokeAnimation1"];} timeInterval:1*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:selfaction:@selector(handlePan:)];self.dragView = [[UIControl alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];self.dragView.center = self.view.center;self.dragView.layer.cornerRadius = CGRectGetWidth(self.dragView.bounds)/2;self.dragView.backgroundColor = [UIColor cyanColor];[self.dragView addGestureRecognizer:recognizer];// 当触目的时候移除动画
    [self.dragView addTarget:selfaction:@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(0, 0) 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:positionAnimationforKey:@"layerPositionAnimation"];}
}@end

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

 

 

 

转载于:https://www.cnblogs.com/YouXianMing/p/3772390.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/493177.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

远比5G发展凶猛!物联网2018白皮书,国内规模已达1.2万亿

来源&#xff1a;智东西摘要&#xff1a;研判物联网的技术产业进展情况&#xff0c;梳理消费物联网、智慧城市物联网、生产性物联网三类物联网应用现状及驱动因素 。在供给侧和需求侧的双重推动下&#xff0c;物联网进入以基础性行业和规模消费为代表的第三次发展浪潮。 5G、 低…

收缩分割多边形(PSENet中有使用)

目的:为了解决密集文本的分割问题 代码: # -*- codingutf-8 -*- import os import cv2 import Polygon as plg import pyclipper import numpy as npdef dist(a, b):return np.sqrt(np.sum((a - b) ** 2))#计算周长 def perimeter(bbox):peri 0.0for i in range(bbox.shape[…

Android 3D emulation 架构理解

Android Emulator 给用户提供 GPU on 选项&#xff0c;意思是利用 Host ( 就是执行 Emulator 的PC机) 的 GPU. 当然PC机必须把 OpenGL 的驱动装好 在实现上就是把 libGLESv1_CM.so libGLESv2.so 替换掉&#xff0c;当system调用 gl的函数的时候&#xff0c;把调用打包为strea…

年度回顾:2018年的人工智能/机器学习惊喜及预测19年的走势

来源&#xff1a;网络大数据考虑到技术变革的速度&#xff0c;我认为让专业IT人士分享他们对2018年最大惊喜及2019年预测的看法会很有趣。以下是他们对人工智能(AI)&#xff0c;机器学习( ML)和其他数据科学迭代的看法&#xff1a;CLARA分析公司首席执行官兼创始人&#xff1a;…

利用dbnet分割条形码与文字(代码+模型)+知识蒸馏+tensorrt推理+利用pyzbar和zxing进行条形码解析

一.DBnet 1.代码链接 分割条形码与文字代码:github链接:GitHub - zonghaofan/dbnet_torch: you can use dbnet to detect word or bar code,Knowledge Distillation is provided,also python tensorrt inference is provided.&#xff08;提供模型&#xff09; 2.论文阅读 …

全球值得关注的11家人脸识别公司与机构

来源&#xff1a;资本实验室根据美国国家标准与技术研究院&#xff08;NIST&#xff09;的2018年全球人脸识别算法测试&#xff08;FRVT&#xff09;最新结果&#xff0c;今年共有来自全球的39家企业和机构参与本次竞赛。在最新排名中&#xff0c;前五名算法被中国公司包揽&…

图论基础知识--最小生成树算法kruskal(克鲁斯克尔)和普里姆算法(Prim算法);最短路径算法Dijkstra(迪杰斯特拉)和Floyd(弗洛伊德)

一.基础知识 有向图 无向图 以无向图为例: 邻接矩阵: 度矩阵(对角矩阵): 二&#xff0e;最小生成树 应用&#xff1a;将网络顶点看着城市&#xff0c;边看着城市之间通讯网&#xff0c;边的权重看着成本&#xff0c;根据最小生成树可以构建城市之间成本最低的通讯网&#x…

算法偏见侦探

来源&#xff1a;AI 科技评论摘要&#xff1a;随着越来越多的算法不断渗透入社会的层层面面&#xff0c;如医疗机构、政府部门&#xff0c;对算法偏见的讨论越来越多。这个月&#xff0c;Nature 杂志评选出 2018 年最受欢迎的十大科学长篇专题报道&#xff0c;其中&#xff0c;…

pytorch实现常用的一些即插即用模块(长期更新)

1.可分离卷积 #coding:utf-8 import torch.nn as nnclass DWConv(nn.Module):def __init__(self, in_plane, out_plane):super(DWConv, self).__init__()self.depth_conv nn.Conv2d(in_channelsin_plane,out_channelsin_plane,kernel_size3,stride1,padding1,groupsin_plane)…

硅片行业:过剩背景下的寡头市场

来源&#xff1a;乐晴智库精选▌竞争格局:过剩背景下的寡头市场&#xff0c;规模壁垒初步形成光伏产业总体处于产能过剩的状态&#xff0c;硅片环节的过剩尤为突出。根据PVInfolink的统计数据&#xff0c;截至2018年2季度末&#xff0c;全球硅片总产能超过160GW&#xff0c;年化…

从attention到Transformer+CV中的self-attention

一.总体结构 由于rnn等循环神经网络有时序依赖&#xff0c;导致无法并行计算&#xff0c;而Transformer主体框架是一个encoder-decoder结构&#xff0c;去掉了RNN序列结构&#xff0c;完全基于attention和全连接。同时为了弥补词与词之间时序信息&#xff0c;将词位置embedding…

12年后,人工智能和人类会是什么样?这是900位专家的看法|报告

来源&#xff1a;机器之能摘要&#xff1a;有分析师预计&#xff0c;到2030年&#xff0c;在复杂的数字系统中&#xff0c;人们将更加依赖于网络人工智能。 有人说&#xff0c;随着对这些网络工具的广泛使用&#xff0c;我们将继续沿着历史的轨迹生活地更好。也有一些人说&…

水印去除(基于nosie2noise优化 代码+模型)

github链接 1.感受野计算: :本层感受野; :上层感受野; :第i层卷积或池化的步长 k:本层卷积核大小 2.空洞卷积卷积核计算:Kk(k-1)(r-1)&#xff0c;k为原始卷积核大小&#xff0c;r为空洞卷积参数空洞率&#xff0c;带入上式即可计算空洞卷积感受野&#xff1b; 3.针对noi…

广度深度都要,亚马逊是如何推动 Alexa 内生成长的?

来源&#xff1a;雷锋网摘要&#xff1a;发展到今天&#xff0c;Alexa 已经成为亚马逊旗下最重要的几个业务支柱之一&#xff0c;尤其是在人工智能语音助手层面&#xff0c;它和 Google Assistant、Apple Siri、Microsoft Cortana 并驾齐驱&#xff0c;甚至在应用场景上有领先之…

剖析云平台中的“共享型数据库”

剖析云计 算中的“共享型数据库” 摘要&#xff1a; 随着云计算的出现&#xff0c;出现了很多新的名词&#xff0c;像云数据库、云存储、弹性扩容&#xff0c;资源隔离等词汇。下面就大家炒的比较热的“共享型数据库”做一下解释&#xff0c;给大家剖析什么叫“共享型数据库”。…

FCOS: A Simple and Strong Anchor-free Object Detector

论文链接 一.背景 1.anchor-base缺点          (&#xff11;)&#xff0e;anchor的设置对结果影响很大,不同项目这些超参都需要根据经验来确定&#xff0c;难度较大&#xff0e; (&#xff12;)&#xff0e;anchor太过密集&#xff0c;其中很多是负样本&#xff…

大数据有十大应用领域,看看你用到了哪个?

来源&#xff1a;网络大数据摘要&#xff1a;如果提到“大数据”时&#xff0c;你会想到什么?也许大部分人会联想到庞大的服务器集群;或者联想到销售商提供的一些个性化的推荐和建议。如今大数据的深度和广度远不止这些&#xff0c;大数据已经在人类社会实践中发挥着巨大的优势…

2018年《环球科学》十大科学新闻出炉:霍金逝世、贺建奎事件位列前二

来源&#xff1a;量子位如果要用两个词来定义2018年的话&#xff0c;我们可能会选择“进步”与“反思”。中国科学在持续进步&#xff0c;克隆猴“中中”与“华华”、单条染色体的酵母&#xff0c;都是世界级的研究成果。“火星快车”在火星上发现大面积的液态湖泊&#xff0c;…

CornerNet: Detecting Objects as Paired Keypoints

CornerNet论文链接 Hourglass Network论文链接 一.背景 1.anchor-base缺点          (&#xff11;)&#xff0e;anchor的设置对结果影响很大,不同项目这些超参都需要根据经验来确定&#xff0c;难度较大&#xff0e; (&#xff12;)&#xff0e;anchor太过密集&…

详细解读什么是自适应巡航?

来源&#xff1a;智车科技摘要&#xff1a;自适应巡航设计初衷是减轻驾驶员长途驾驶的疲劳&#xff0c;极为复杂的城市路况并不是它发挥作用的地方。虽然现在的自适应巡航系统具备了根据前车情况、根据路况减速&#xff0c;甚至是刹停的功能&#xff0c;不过其开发之初便是为了…