BaseControl按钮合集
BaseControl按钮合集
效果
源码
https://github.com/YouXianMing/Animations
// // POPBaseControl.h // Animations // // Created by YouXianMing on 16/5/26. // Copyright © 2016年 YouXianMing. All rights reserved. // #import <UIKit/UIKit.h> @class POPBaseControl;@protocol POPBaseControlDelegate <NSObject>/*** 缩放百分比事件** @param controll PressControll对象* @param percent 百分比*/ - (void)POPBaseControl:(POPBaseControl *)controll currentPercent:(CGFloat)percent;/*** 事件触发** @param controll PressControll对象*/ - (void)POPBaseControlEvent:(POPBaseControl *)controll;@end@interface POPBaseControl : UIView/*** 代理*/ @property (nonatomic, weak) id <POPBaseControlDelegate> delegate;/*** 动画时间,默认值为0.4*/ @property (nonatomic) CFTimeInterval animationDuration;/*** 目标对象*/ @property (nonatomic, weak) id target;/*** 事件*/ @property (nonatomic) SEL selector;/*** 是否有效*/ @property (nonatomic) BOOL enabled;/*** 是否选中*/ @property (nonatomic) BOOL selected;#pragma mark - Properties used by SubClass & Methods Overwrite by subClass./*** 容器view,用于子类添加控件*/ @property (nonatomic, strong, readonly) UIView *contentView;/*** 当前动画比例(子类继承的时候重载)** @param percent 比例*/ - (void)currentPercent:(CGFloat)percent;/*** 事件激活了*/ - (void)controllEventActived;@end
// // POPBaseControl.m // Animations // // Created by YouXianMing on 16/5/26. // Copyright © 2016年 YouXianMing. All rights reserved. // #import "POPBaseControl.h" #import "POP.h"@interface POPBaseControl ()@property (nonatomic, strong) UIView *absView; @property (nonatomic, strong) UIButton *button; @property (nonatomic, strong) UIView *contentView;@property (nonatomic) CGFloat percent;@end@implementation POPBaseControl- (void)layoutSubviews {[super layoutSubviews];_button.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);_contentView.bounds = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); }- (instancetype)initWithFrame:(CGRect)frame {if (self = [super initWithFrame:frame]) {// 动画时间_animationDuration = 0.4f;// 隐身的view_absView = [[UIView alloc] init];_absView.userInteractionEnabled = NO;_absView.backgroundColor = [UIColor clearColor];[self addSubview:_absView];// 容器View_contentView = [[UIView alloc] initWithFrame:self.bounds];_contentView.userInteractionEnabled = NO;[self addSubview:_contentView];// 按钮_button = [[UIButton alloc] initWithFrame:self.bounds];[self addSubview:_button];// 按钮事件[_button addTarget:self action:@selector(touchBeginOrTouchDragEnter) forControlEvents:UIControlEventTouchDown | UIControlEventTouchDragEnter];[_button addTarget:self action:@selector(touchUpInside) forControlEvents:UIControlEventTouchUpInside];[_button addTarget:self action:@selector(touchDragExitOrTouchCancel) forControlEvents:UIControlEventTouchDragExit | UIControlEventTouchCancel];}return self; }#pragma mark - Animations.- (void)touchUpInside {[self touchDragExitOrTouchCancel];[self controllEventActived];if (self.target && self.selector) {#pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks"[self.target performSelector:self.selector withObject:self]; #pragma clang diagnostic pop}if (self.delegate && [self.delegate respondsToSelector:@selector(POPBaseControlEvent:)]) {[self.delegate POPBaseControlEvent:self];} }- (void)touchDragExitOrTouchCancel {[_absView.layer pop_removeAllAnimations];POPBasicAnimation *scaleAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerOpacity];scaleAnimation.toValue = @(1);scaleAnimation.delegate = self;scaleAnimation.duration = _animationDuration;[_absView.layer pop_addAnimation:scaleAnimation forKey:nil]; }- (void)touchBeginOrTouchDragEnter {[_absView.layer pop_removeAllAnimations];POPBasicAnimation *scaleAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerOpacity];scaleAnimation.toValue = @(0);scaleAnimation.delegate = self;scaleAnimation.duration = _animationDuration;[_absView.layer pop_addAnimation:scaleAnimation forKey:nil]; }#pragma mark - POPAnimation's delegate.- (void)pop_animationDidApply:(POPAnimation *)anim {NSNumber *toValue = (NSNumber *)[anim valueForKeyPath:@"currentValue"];_percent = (toValue.floatValue - [POPBaseControl calculateConstantWithX1:0 y1:1 x2:1 y2:0]) / [POPBaseControl calculateSlopeWithX1:0 y1:1 x2:1 y2:0];[self currentPercent:_percent]; }#pragma mark - Overwrite by subClass.- (void)currentPercent:(CGFloat)percent {}- (void)controllEventActived {}#pragma mark - Math.+ (CGFloat)calculateSlopeWithX1:(CGFloat)x1 y1:(CGFloat)y1 x2:(CGFloat)x2 y2:(CGFloat)y2 {return (y2 - y1) / (x2 - x1); }+ (CGFloat)calculateConstantWithX1:(CGFloat)x1 y1:(CGFloat)y1 x2:(CGFloat)x2 y2:(CGFloat)y2 {return (y1*(x2 - x1) - x1*(y2 - y1)) / (x2 - x1); }#pragma mark - setter & getter.@synthesize enabled = _enabled;- (void)setEnabled:(BOOL)enabled {_button.enabled = enabled; }- (BOOL)enabled {return _button.enabled; }@synthesize selected = _selected;- (void)setSelected:(BOOL)selected {_button.selected = selected; }- (BOOL)selected {return _button.selected; }@end
说明
本人一共封装了3种按钮的基类控件,以上是一个示例演示,演示如何通过继承来实现想要的效果.
转载于:https://www.cnblogs.com/YouXianMing/p/5532116.html
BaseControl按钮合集相关推荐
- 5去掉button按钮的点击样式_各种好看的小按钮合集,纯css编写,最近在学习时遇到的,记录成为笔记...
写在前面 最近忙着实习的事,前往广州,租房,置办东西等等.用碎片化的时间看了一些博客,也看到不少我认为很不错的通过纯css来打造的按钮样式.记录下来以后开发的时候或许能用上. 亮起来按钮 <di ...
- button按钮样式_各种好看的小按钮合集,纯css编写,最近在学习时遇到的,记录成为笔记...
写在前面 最近忙着实习的事,前往广州,租房,置办东西等等.用碎片化的时间看了一些博客,也看到不少我认为很不错的通过纯css来打造的按钮样式.记录下来以后开发的时候或许能用上. 亮起来按钮 < 简 ...
- Android 悬浮菜单(按钮) BoomMenu(样式大合集)
Android 悬浮菜单 BoomMenu(样式大合集) 一.样式大集合:(总有一款适合你) BoomMenu 使用 一.Demo 效果演示: 二.导入引用 dependencies { - comp ...
- Boom Library 93套影视游戏无损配乐音效素材合集包
Boom Library 93套影视游戏无损配乐音效素材合集包 素材压缩包大小共:851G 每个合集为独立压缩包 可选择性下载 云桥网络 平台获取合集包 01.BOOM Library Assault ...
- 最新最全的 Android 开源项目合集(一)
原文链接:https://github.com/opendigg/awesome-github-android-ui 抽屉菜单 MaterialDrawer ★7337 - 安卓抽屉效果实现方案 Si ...
- python在windows的开发环境_Python合集之Python开发环境在Windows系统里面搭建
在上一个合集里面我们了解到了Python的基础信息及学习了Python对我们有什么用处,那么今天我们来了解一下,Python的开发环境该如何搭建.(注:Python的开发环境可以在Windows.MA ...
- 云栖Android精华文章合集
云栖Android精彩文章整理自各位技术大咖们关于Android的精彩分享,本文将云栖Android精彩文章整理成为一个合集,以便于大家学习参考.Weex.apk瘦身.开发资源.应用维护.内存管理,一 ...
- Web测试到底是在测什么(资料合集)
http://www.cnblogs.com/idotest/p/6838583.html 图片略模糊 看得清就好 Web测试, 进行抽离拆分,基本上就如上一些内容. 不管是测什么系统,什么功能,基本 ...
- Jerry的ABAP原创技术文章合集
我之前发过三篇和ABAP相关的文章: 1. Jerry的ABAP, Java和JavaScript乱炖 这篇文章包含我多年来在SAP成都研究院使用ABAP, Java和JavaScript工作过程中的 ...
最新文章
- git 常用命令 方法大全
- python网络通信框架_Python运维-Socket网络编程 (1)
- 提高mysql千万级大数据SQL查询优化30条经验
- python(numpy,pandas6)——pandas数据形式的简介,排序方式sort_index,sort_values
- ubuntu mysql master slave_Ubuntu下MySQL5.5 配置主从(Master Slave)同步
- 基于mysql搭建框架环境搭建_Maven+Spring+Spring MVC+MyBatis+MySQL,搭建SSM框架环境
- 还要我带一个六级辅导班--痛苦!
- python threading.Thread
- Qt 去除控件边框线
- java笔试题及答案
- dos2unix 安装和使用
- Luogu P4727 [HNOI2009]图的同构记数
- 解决go get时,遇到unrecognized import path的问题
- java excel换行_java poi出excel换行问题
- [02.20][中国][人再囧途之泰囧][HD-RMVB.720p.国语中字][2012年喜剧]
- 代码查重 EOJ Monthly 2018.4
- MySQL单表数据量过大的处理方式经验
- 毛球科技细说隔离见证
- javascript H5解决手机拍照图片被旋转问题
- 微信公众平台企业号验证接口、回调 PHP版
热门文章
- Spring Boot MongoDB 入门
- switch多值匹配骚操作,带你涨姿势!
- Zuul(SpringCloud学习笔记一)
- 数据库:悲观锁与乐观锁
- mysql求女生人数_在读女硕士110多万!为什么越来越多的女生选择考研?
- python生成报告_python生成测试报告
- 将文件名发送到服务器,将Paperclip路径文件名从服务器更新到s3(Updating Paperclip path file names from on server to s3)...
- oracle和dba,oracle db、dba和rdba
- 运维人员 | 需要了解的数据中心的网络威胁
- 综合布线成数据中心建设和运营的重要课题