UIButton点击动画 ---pop动画
来源:互联网 发布:嵌入式linux终端 编辑:程序博客网 时间:2024/05/20 02:21
@interface FlatButton : UIButton
重写构造方法
+ (instancetype)button{ return [self buttonWithType:UIButtonTypeCustom];}- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { [self setup]; } return self;}-(id)initWithCoder:(NSCoder *)aDecoder{ self = [super initWithCoder:aDecoder]; if (self) { [self setup]; } return self;}
添加响应
//添加按下和进入的响应 [self addTarget:self action:@selector(scaleToSmall) forControlEvents:UIControlEventTouchDown | UIControlEventTouchDragEnter]; //添加按下的响应 [self addTarget:self action:@selector(scaleAnimation) forControlEvents:UIControlEventTouchUpInside]; //添加划出button范围的响应 [self addTarget:self action:@selector(scaleToDefault) forControlEvents:UIControlEventTouchDragExit];
UIControlEventTouchDragExit 手指离开边界回调
An event where a finger is dragged from within a control to outside its bounds.
但是实际却是离开button边界70左右才回调
接下来使用到pop动画
- (void)scaleToSmall{ NSLog(@"scaletoSmall"); POPBasicAnimation *scaleAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerScaleXY]; scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(0.95f, 0.95f)]; [self.layer pop_addAnimation:scaleAnimation forKey:@"layerScaleSmallAnimation"];}- (void)scaleAnimation{ NSLog(@"scaleAnimation"); POPSpringAnimation *scaleAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY]; scaleAnimation.velocity = [NSValue valueWithCGSize:CGSizeMake(6.f, 6.f)]; scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(1.f, 1.f)]; scaleAnimation.springBounciness = 22.0f; [self.layer pop_addAnimation:scaleAnimation forKey:@"layerScaleSpringAnimation"];}- (void)scaleToDefault{ NSLog(@"scaletoDefault"); POPBasicAnimation *scaleAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerScaleXY]; scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(1.f, 1.f)]; [self.layer pop_addAnimation:scaleAnimation forKey:@"layerScaleDefaultAnimation"];}
设置一下标题偏移
- (UIEdgeInsets)titleEdgeInsets{ //top, left, bottom, right return UIEdgeInsetsMake(4.f, 28.f, 4.f, 28.f);}
控件的内置大小 --- 由控件本身的内容所决定的
- (CGSize)intrinsicContentSize{ CGSize s = [super intrinsicContentSize]; return CGSizeMake(s.width + self.titleEdgeInsets.left + self.titleEdgeInsets.right, s.height + self.titleEdgeInsets.top + self.titleEdgeInsets.bottom); }
0 0
- UIButton点击动画 ---pop动画
- pop动画
- pop动画
- UIButton 动画移动 过程中 不能点击
- 自定义转场动画 pop动画
- iOS 自定义UIButton点击动画特效 —— HERO博客
- 一行代码为你的UIBUtton添加点击弹性动画
- ios push pop动画
- pop动画实践(一)
- ios pop 折叠动画
- ios pop系统动画
- Pop动画丢失问题
- 动画引擎pop
- 简单实用POP动画
- 自定义Pop动画
- pop动画原理详解
- pop 阻尼动画效果
- POP弹性动画效果
- 极简的配置单节点Kubernetes(k8s)集群
- Reversible Primes (20)stoi应用
- 架构师米洛:如何让你的同事对你越来越好
- 面试/笔试数据结构之排序算法篇
- 菱形继承和虚继承
- UIButton点击动画 ---pop动画
- 1html的基本结构
- 看Kubernetes 1.5之后如何称霸容器编排管理界
- [Tarjan算法]最近公共祖先(LCA)问题求解
- apk反编译
- 详述 Java 语言中的大数值
- system、runtime
- lesson6 基于多线程的tcp并发服务器
- Redis的安装和部署