POP按钮动画
POP按钮动画
效果
源码
https://github.com/YouXianMing/Animations
//
// ButtonPressViewController.m
// Facebook-POP-Animation
//
// Created by YouXianMing on 15/11/16.
// Copyright © 2015年 ZiPeiYi. All rights reserved.
// #import "ButtonPressViewController.h"
#import "POP.h"
#import "UIColor+CustomColors.h"
#import "StrokeCircleLayerConfigure.h"
#import "FillCircleLayerConfigure.h"
#import "GCD.h" @interface ButtonPressViewController () @property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) CAShapeLayer *circleShape1;
@property (nonatomic, strong) CAShapeLayer *circleShape2; @property (nonatomic, strong) UILabel *label; @end @implementation ButtonPressViewController - (void)viewDidLoad { [super viewDidLoad]; [self setup];
} #pragma mark - setup
- (void)setup { self.view.backgroundColor = [UIColor whiteColor]; // 完整显示按住按钮后的动画效果
_button = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
_button.layer.cornerRadius = .f;
_button.backgroundColor = [UIColor cyanColor];
_button.center = self.view.center;
[self.view addSubview:_button]; self.label = [[UILabel alloc] initWithFrame:_button.bounds];
self.label.font = Font_HYQiHei();
self.label.textAlignment = NSTextAlignmentCenter;
self.label.text = @"0%";
[self.button addSubview:self.label]; // 按住按钮后没有松手的动画
[_button addTarget:self
action:@selector(scaleToSmall)
forControlEvents:UIControlEventTouchDown | UIControlEventTouchDragEnter]; // 按住按钮松手后的动画
[_button addTarget:self
action:@selector(scaleAnimations)
forControlEvents:UIControlEventTouchUpInside]; // 按住按钮后拖拽出去的动画
[_button addTarget:self
action:@selector(scaleToDefault)
forControlEvents:UIControlEventTouchDragExit]; // 圆环1
{
self.circleShape1 = [CAShapeLayer layer];
self.circleShape1.strokeEnd = .f;
StrokeCircleLayerConfigure *config = [StrokeCircleLayerConfigure new];
config.lineWith = 0.5f;
config.startAngle = ;
config.endAngle = M_PI * ;
config.radius = .f;
config.circleCenter = self.view.center;
[config configCAShapeLayer:self.circleShape1];
[self.view.layer addSublayer:self.circleShape1];
} // 圆环2
{
self.circleShape2 = [CAShapeLayer layer];
self.circleShape2.strokeEnd = .f;
StrokeCircleLayerConfigure *config = [StrokeCircleLayerConfigure new];
config.lineWith = 0.5f;
config.startAngle = ;
config.endAngle = M_PI * ;
config.radius = .f;
config.clockWise = YES;
config.circleCenter = self.view.center;
[config configCAShapeLayer:self.circleShape2];
[self.view.layer addSublayer:self.circleShape2];
}
} #pragma mark - Button events
- (void)scaleToSmall { [_button.layer pop_removeAllAnimations]; // 变小尺寸
POPBasicAnimation *scaleAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerScaleXY];
scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(0.7f, 0.7f)];
scaleAnimation.delegate = self;
[_button.layer pop_addAnimation:scaleAnimation forKey:nil]; // 颜色
POPSpringAnimation *backgroundColor = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBackgroundColor];
backgroundColor.toValue = (id)[UIColor magentaColor].CGColor;
[_button.layer pop_addAnimation:backgroundColor forKey:@"magentaColor"];
} - (void)scaleAnimations { [_button.layer pop_removeAllAnimations]; // 恢复尺寸
POPBasicAnimation *scaleAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerScaleXY];
scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(.f, .f)];
scaleAnimation.delegate = self;
[_button.layer pop_addAnimation:scaleAnimation forKey:nil]; // 颜色
POPSpringAnimation *backgroundColor = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBackgroundColor];
backgroundColor.toValue = (id)[UIColor cyanColor].CGColor;
[_button.layer pop_addAnimation:backgroundColor forKey:nil];
} - (void)scaleToDefault{ [_button.layer pop_removeAllAnimations]; // 恢复尺寸
POPBasicAnimation *scaleAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerScaleXY];
scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(.f, .f)];
scaleAnimation.delegate = self;
[_button.layer pop_addAnimation:scaleAnimation forKey:nil]; // 颜色
POPSpringAnimation *backgroundColor = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBackgroundColor];
backgroundColor.toValue = (id)[UIColor cyanColor].CGColor;
[_button.layer pop_addAnimation:backgroundColor forKey:nil];
} #pragma mark - POP delegate
- (void)pop_animationDidStart:(POPAnimation *)anim { NSLog(@"pop_animationDidStart %@", anim);
} - (void)pop_animationDidReachToValue:(POPAnimation *)anim { NSLog(@"pop_animationDidReachToValue %@", anim);
} - (void)pop_animationDidStop:(POPAnimation *)anim finished:(BOOL)finished { NSLog(@"pop_animationDidStop %@", anim); } - (void)pop_animationDidApply:(POPAnimation *)anim { NSLog(@"pop_animationDidApply %@", anim); NSValue *toValue = (NSValue *)[anim valueForKeyPath:@"currentValue"];
CGSize size = [toValue CGSizeValue]; CGFloat percent = (size.height - calculateConstant(, , , 0.7))/calculateSlope(, , , 0.7);
_circleShape1.strokeEnd = percent;
_circleShape2.strokeEnd = percent; double showValue = fabs(percent * );
self.label.text = [NSString stringWithFormat:@"%.f%%", showValue];
} #pragma mark - Y = kX + b
CGFloat calculateSlope(CGFloat x1, CGFloat y1, CGFloat x2, CGFloat y2) { return (y2 - y1) / (x2 - x1);
} CGFloat calculateConstant(CGFloat x1, CGFloat y1, CGFloat x2, CGFloat y2) { return (y1*(x2 - x1) - x1*(y2 - y1)) / (x2 - x1);
} @end
细节
处理好POP动画的代理即可.
POP按钮动画的更多相关文章
- 5个基于css3超炫的鼠标滑动按钮动画
今天给大家分享5个基于css3超炫的鼠标滑动按钮动画.这5个按钮鼠标经过的时候有超炫的动画效果.这5个按钮适用浏览器:360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之 ...
- 8款超酷而实用的CSS3按钮动画
1.CSS3分享按钮动画特效 这是一款基于CSS3的社会化分享按钮,按钮非常简单,提供了分享到twitter.facebook.youtube等大型社交网站.每一个分享按钮都有个大社交网站的Logo图 ...
- iOS利用Runtime自定义控制器POP手势动画
前言 苹果在iOS 7以后给导航控制器增加了一个Pop的手势,只要手指在屏幕边缘滑动,当前的控制器的视图就会跟随你的手指移动,当用户松手后,系统会判断手指拖动出来的大小来决定是否要执行控制器的Pop操 ...
- pop弹簧动画实现
POP是一个在iOS与OS X上通用的极具扩展性的动画引擎.它在基本的静态动画的基础上增加的弹簧动画与衰减动画,使之能创造出更真实更具物理性的交互动画.POP的API可以快速的与现有的ObjC代码集成 ...
- POP缩放动画
POP缩放动画 效果 源码 https://github.com/YouXianMing/Animations // // SpringScaleViewController.m // Animati ...
- POP数值动画
POP数值动画 效果 源码 https://github.com/YouXianMing/Animations // // PopNumberController.m // Animations // ...
- 简单的UIButton按钮动画效果iOS源码
这个是简单的UIButton按钮动画效果案例,源码,简单的UIButton按钮动画,可以自定义button属性. 效果图: <ignore_js_op> 使用方法: 使用时把ButtonA ...
- uwp - 做一个相对炫酷的动画按钮/按钮动画
原文:uwp - 做一个相对炫酷的动画按钮/按钮动画 看腻了系统自带的button animation何不尝试下自定义一个较为炫酷的动画顺便提升用户体验.效果图: 动画分为几个部分,分别是:内圆从中心 ...
- Unity中的动画系统和Timeline(2) 按钮动画和2D精灵动画
按钮动画 1 创建按钮后,按钮的Button组件中,Transition我们平时用的时Tint,这次选择Animation 选择Auto Generate Animation,创建一个按钮动画 2 后 ...
随机推荐
- 一步一步学习IdentityServer4 (6) Connect-OpenId Cookies SignIn SignOut 那些事
先来看下下面的配置: JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); services.AddAuthentication( o ...
- scrapy 设置cookie池
代码已经很详细了,可以直接拿来使用了. 包含了: 从网页获取cookie 存入mongodb 定期删除cookie scrapy中间件对cookie池的取用 #!/usr/bin/python #co ...
- asp.net MVC发布iis无法加载css,js和图片
今天真够郁闷的,遇到了在本地能运行的项目到了iis服务器那里就不行了,无法加载css,js和图片,这里说清楚一下先,关于asp.net 的MVC中这样的情况其实不少,但是之前遇到的是在visual s ...
- USACO 4.3 Street Race
Street RaceIOI'95 Figure 1 gives an example of a course for a street race. You see some points, labe ...
- Haproxy 开启日志记录
CentOS 7上yum安装的Haproxy,默认没有记录日志.需要做一下配置才能记录日志.(不知道其他版本是否需要,已经忘记了)主要是用到了Haproxy,以前貌似没有这么麻烦,今天配置出了一些问题 ...
- 同一个IP不同端口号使用session失效
背景 我有两个工程projectA.projectB,projectA放在TomcatA中,projectB放在TomcatB中,TomcatA.TomcatB在一台server上. 工程都映射的根路 ...
- Python并发编程系列之常用概念剖析:并行 串行 并发 同步 异步 阻塞 非阻塞 进程 线程 协程
1 引言 并发.并行.串行.同步.异步.阻塞.非阻塞.进程.线程.协程是并发编程中的常见概念,相似却也有却不尽相同,令人头痛,这一篇博文中我们来区分一下这些概念. 2 并发与并行 在解释并发与并行之前 ...
- HTTP 的请求过程?
当点击一个链接时,浏览器首先找到站点的IP地址,这是通过DNS来实现的,在找到IP地址后就可以建立TCP连接了,连接建立后我们就可以发送请求了.但这个请求是什么样子的呢 ? 我们现在假设点击了一个从 ...
- vsftp 虚拟用户+MySQL认证独立家目录
centos7 系统 安装包 yum -y install mariadb vsftpd openssl-devel mysql-devel pam-devel yum -y groupinsta ...
- Kubernetes网络模型概念
Kubernetes网络模型 Kubernetes网络模型设计的一个基础原则是:每个Pod都拥有一个独立的IP地址,而且假定所有Pod都在一个可以直接连通的.扁平的网络空间中.所以不管它们是否运行在同 ...