日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

BaseControl按钮合集

發(fā)布時間:2025/3/21 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BaseControl按钮合集 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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;/*** 事件觸發(fā)** @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種按鈕的基類控件,以上是一個示例演示,演示如何通過繼承來實現(xiàn)想要的效果.

?

轉(zhuǎn)載于:https://www.cnblogs.com/YouXianMing/p/5532116.html

總結(jié)

以上是生活随笔為你收集整理的BaseControl按钮合集的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。