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 后 ...
随机推荐
- 2015 icpc北京赛区 D 最小割
题目大意:给你一棵技能树,如果要学习一个技能,那么它之前的技能要全部学完,第 i 个点需要ai 能学习 每条边有一个消耗c 如果支付c那么就能去掉这条边, 你还可以kejin 花费di 就能直接学习 ...
- 如何使用django显示一张图片
django显示图片对新手来说真的算是一个坑.. 这里记录下小白爬坑的历程. 首先,你需要一个可以运行的django服务器,能显示正常的html文本,无法显示图片 这是html的文本,可以显示文字,无 ...
- ubuntu 安装 Sqlite 和 可视化工具 SqliteBroswer
ubuntu 安装 Sqlite 和 可视化工具 SqliteBroswer 下载sqlite www.sqlite.org/download.html 安装Sqlite 创建一个目录: ...
- windows下mysql配置(第一次)
忙活了大半天,总算配置好了,本文献给windows下没试用过Mysql的小白,勿喷 http://blog.csdn.net/z1074907546/article/details/51482718 ...
- imageio 载入 Buffer 格式的图片
题注:OpenCV 使用 pip install -U opencv-python 即可安装. import zipfile import imageio import cv2 # 载入压缩文件 Z ...
- CSS 显示或隐藏子元素
很多时候我们仅仅只是想让鼠标移动入某个元素,然后显示出某个元素. 大多数博客的标题或内容都是:使用CSS实现鼠标悬停在一行上,显示某些元素 很遗憾,这是错误的,鼠标悬停后,尽管CSS标准中有定义此种方 ...
- Django的Form机制小问题
使用Django,我们可以以声明式的方式来定义一个Form,如下: 1 2 3 4 5 # -*- coding: utf-8 -*- from django import forms class S ...
- C++下的强制转换类型
一.static_cast static_cast,静态类型转换. 下面,我举几个例子,大家就能清楚了. int main(int argc, char const *argv[]) { char ...
- [BZOJ5125]小Q的书架(决策单调性+分治DP+树状数组)
显然有决策单调性,但由于逆序对不容易计算,考虑分治DP. solve(k,x,y,l,r)表示当前需要选k段,待更新的位置为[l,r],这些位置的可能决策点区间为[x,y].暴力计算出(l+r)/2的 ...
- [BZOJ4668]冷战(并查集)
比较自然的思路是,由于需要记录连通块合并时的信息,所以需要建出Kruskal重构树. 需要用LCT维护,支持加点和在线LCA操作. 不妨考虑在并查集合并的同时记录信息,pre[x]表示x与它的父亲相连 ...