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(, , self.frame.size.width, self.frame.size.height);
_contentView.bounds = CGRectMake(, , 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 = @();
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 = @();
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: y1: x2: y2:]) / [POPBaseControl calculateSlopeWithX1: y1: x2: y2:]; [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种按钮的基类控件,以上是一个示例演示,演示如何通过继承来实现想要的效果.

BaseControl按钮合集的更多相关文章
- Android 自定义View合集
自定义控件学习 https://github.com/GcsSloop/AndroidNote/tree/master/CustomView 小良自定义控件合集 https://github.com/ ...
- 不容错过的UI设计素材大合集
免费PSD素材 TETHR by InVision 这是出自InVision的8款PSD文件,其中包含了100个模板和超过500个UI控件.来自InVision和UI8的设计师一同协作完成了这套UI ...
- Android中的对话框AlertDialog使用技巧合集-转载
Android中的对话框AlertDialog使用技巧合集 文章来自:http://blog.csdn.net/blue6626/article/details/6641105 今天我用自 ...
- Web测试到底是在测什么(资料合集)
开始今晚的主题之前 先来看一张图, 这是老徐16年10月份,线上Web主题分享时整理的大纲 图片略模糊 看得清就好 Web测试, 进行抽离拆分,基本上就如上一些内容. 不管是测什么系统,什么功能,基本 ...
- FFmpeg示例程序合集-批量编译脚本
此前做了一系列有关FFmpeg的示例程序,组成了<最简单的FFmpeg示例程序合集>,其中包含了如下项目:simplest ffmpeg player: ...
- 【Oracle教程资源大合集】Oracle数据库免费学习资源汇总
Oracle的产品非常丰富,各类学习资源也五花八门,本文将介绍Oracle官方的免费教程与风哥整理的Oracle视频教程: 1.Oracle帮助中心 Oracle帮助中心也称为Oracle文档中心,这 ...
- 24个 CSS 高级技巧合集
上期入口:史上最全实用网络爬虫合集! 1.使用CSS复位 CSS复位可以在不同的浏览器上保持一致的样式风格.您可以使用CSS reset 库Normalize等,也可以使用一个更简化的复位方法: ** ...
- Power BI 3-4月功能更新培训合集
Power BI 3-4月功能更新培训合集 Power BI每月功能的更新,都有很多大咖精辟解读,我们一直也都是积极中期待,相信所有P友如是或更甚. 视频学习可以结合微软Power BI 3-4月文 ...
- 常用的js代码合集
!function(util){ window.Utils = util(); }( function(){ //document_event_attributes var DEA = "d ...
随机推荐
- LeetCode(16):最接近的三数之和
Medium! 题目描述: 给定一个包括 n 个整数的数组 nums 和 一个目标值 target.找出 nums 中的三个整数,使得它们的和与 target 最接近.返回这三个数的和.假定每组输入只 ...
- Laravel Model 的 fillable (白名单)与 guarded (黑名单)
例如 protected $fillable = ['name']; protected $guarded = ['price']; 定义了 name 字段可以写入/修改,而 price 字段不可以. ...
- BZOJ 1934 Vote 善意的投票(最小割+二分图)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1934 题目大意: 幼儿园里有n个小朋友打算通过投票来决定睡不睡午觉.对他们来说,这个问题 ...
- watch案例解析(element-ui el-select 无法选中问题剖析)
fire 读在最前面: 1.此文章衔接Vue 虚拟Dom 及 部分生命周期初探,相关整体知识点请先阅读后再继续本文阅读 问:子组件中明明有watch value,为什么this.$emit('inpu ...
- .NetCore WebApi利用Swagger文档实现选择文件上传
介绍 实现这个功能主要还是依赖过滤器 在Swagger中利用 IOperationFilter 操作来实现文件上传 与之前处理结合Idr4授权一样的处理方式,不同的是授权处理的是Security,而文 ...
- IScroll5安卓重复点击兼容问题处理
最近在做移动web开发,使用IScroll 5 的时候出现了设备之间兼容的问题: 情景如下: Android手机:点击滚动区间内的选项时出现点击时间重叠(类似事件冒泡的行为)问题 Apple手机:木有 ...
- JQuery 获取除某指定对象外的其他对象 :not() 与.not()
.not() 遍历方法 从匹配元素集合中移除元素 :not() 选择器 选取除了指定元素以外的所有元素 .siblings() 遍历方法 返回被选元素的所有同级元素 需排除对象单数个(1个) 获取 ...
- HDU4267 树状数组
题意描述: 给定一个数组,有两种操作: 操作一:a b k c 对于区间a~b之间的元素如果下标满足(i-a)%k=0则给元素i加上c 操作二:a 查询下标为a的元素当前值 解题思路 ...
- Java之路(五) 访问权限控制
在Java中,所有事物都具有某种形式的访问权限控制. 访问权限的控制等级从最大到最小依次为:public,protected,包访问权限(无关键词)和private. public,protected ...
- jenkins自动构建部署
环境 centos7 tomcat8.5.37 maven3.3.9 jdk8 git1.8.3.1 安装jdk,tomcat,maven,git(环境变量,配置文件什么的自行百度) ...