设为首页 加入收藏

TOP

BaseControl按钮合集(一)
2017-10-13 10:28:48 】 浏览:2092
Tags: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 controllEve
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇根据字符串链接_二维码生成 下一篇iOS进阶学习-多媒体

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目