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 后 ...
随机推荐
- CF 586A 找1的个数和101的个数
Sample test(s) input 50 1 0 1 1 output 4 input 71 0 1 0 0 1 0 output 4 input 10 output 0 # include & ...
- day6 ConfigParser模块 yaml模块
yaml模块: python可以处理yaml文件,yaml文件安装的方法为:$ pip3 install pyyaml configparser模块,用来处理文件的模块,可以实现文件的增 ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) E - Aquarium decoration 贪心 + 平衡树
E - Aquarium decoration 枚举两个人都喜欢的个数,就能得到单个喜欢的个数,然后用平衡树维护前k大的和. #include<bits/stdc++.h> #define ...
- JS学习笔记(二)变量、作用域及内存问题
一.基本类型和引用类型的值 变量可能包含两种不同数据类型的值:基本类型值和引用类型值. 基本类型值:简单的数据段. 引用类型值:可能由多个值构成的对象. 当将一个值赋给变量时,解析器必须确定这个值是基 ...
- OSPF详解
OSPF 详解 (1) [此博文包含图片] (2013-02-04 18:02:33) 转载 ▼ 标签: 端的 第二 以太 第一个 正在 目录 序言 初学乍练 循序渐进学习OSPF 朱皓 入门之前 了 ...
- js缓存加密
1.访问A链接就以A链接的特定部分为密码盐,生成一个js跳转配置文件名 aojoweiojoiwjeiof2.PHP在生成js跳转文件名的时候,也是根据数据库中的跳转起始链接特定部分作为盐,生成的文件 ...
- 20172304 实验二 《Java面向对象程序设计》 实验报告
20172304 实验二 <Java面向对象程序设计> 实验报告 课程名称:<程序设计与数据结构> 学生班级:1723班 学生姓名:段志轩 学生学号:20172304 实验时间 ...
- Bunch 转换为 HDF5 文件:高效存储 Cifar 等数据集
关于如何将数据集封装为 Bunch 可参考 关于 『AI 专属数据库的定制』的改进. PyTables 是 Python 与 HDF5 数据库/文件标准的结合.它专门为优化 I/O 操作的性能.最大限 ...
- CodeForces - 725D Contest Balloons 贪心
D. Contest Balloons time limit per test 3 seconds memory limit per test 2 ...
- C# 操作 access 数据库
随笔: (1) 命名空间 using System.Data.OleDb; (2) 连接字符串 private staticstring connStr = @"Provider= ...