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 controllEve