chore: Initial clean commit
- Removed YuMi/Library/ (138 MB, not tracked) - Removed YuMi/Resources/ (23 MB, not tracked) - Removed old version assets (566 files, not tracked) - Excluded Pods/, xcuserdata/ and other build artifacts - Clean repository optimized for company server deployment
This commit is contained in:
48
YuMi/Tools/CountDown/CountDownHelper.h
Normal file
48
YuMi/Tools/CountDown/CountDownHelper.h
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// CountDownHelper.h
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by 冯硕 on 2021/9/15.
|
||||
// 倒计时
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol CountDownHelperDelegate <NSObject>
|
||||
@optional
|
||||
///倒计时结束
|
||||
- (void)onCountdownFinish;
|
||||
///倒计时进行
|
||||
- (void)onCountdownOpen:(int)time;
|
||||
///顺计时结束
|
||||
- (void)onClockwiseFinish;
|
||||
///顺计时进行
|
||||
- (void)onClockwiseOpen:(CGFloat)time;
|
||||
@end
|
||||
|
||||
|
||||
@interface CountDownHelper : NSObject
|
||||
///倒计时是否完成
|
||||
@property (nonatomic,assign) BOOL isCountdownFinish;
|
||||
///顺计时的秒数
|
||||
@property (nonatomic,assign) CGFloat seconds;
|
||||
///代理
|
||||
@property (nonatomic,weak) id<CountDownHelperDelegate> delegate;
|
||||
|
||||
///单例
|
||||
+ (instancetype)shareHelper;
|
||||
// 停止倒计时
|
||||
- (void)stopCountDown;
|
||||
///开始倒计时
|
||||
- (void)openCountdownWithTime:(int)totalTime;
|
||||
|
||||
// 停止顺计时
|
||||
- (void)stopClockwise;
|
||||
///开始顺计时
|
||||
- (void)openClockwiseWithTime:(int)totalTime;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
132
YuMi/Tools/CountDown/CountDownHelper.m
Normal file
132
YuMi/Tools/CountDown/CountDownHelper.m
Normal file
@@ -0,0 +1,132 @@
|
||||
//
|
||||
// CountDownHelper.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by 冯硕 on 2021/9/15.
|
||||
//
|
||||
|
||||
#import "CountDownHelper.h"
|
||||
|
||||
@interface CountDownHelper ()
|
||||
@property (strong, nonatomic) dispatch_source_t timer;
|
||||
@property (strong, nonatomic) dispatch_source_t clockwiseTimer;
|
||||
@end
|
||||
|
||||
@implementation CountDownHelper
|
||||
-(void)dealloc{
|
||||
[self stopCountDown];
|
||||
}
|
||||
-(instancetype)init{
|
||||
self = [super init];
|
||||
if(self){
|
||||
self.isCountdownFinish = YES;
|
||||
self.seconds = 1.0;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
+ (instancetype)shareHelper {
|
||||
static dispatch_once_t onceToken;
|
||||
static CountDownHelper * helper = nil;
|
||||
dispatch_once(&onceToken, ^{
|
||||
helper = [[CountDownHelper alloc] init];
|
||||
});
|
||||
return helper;
|
||||
}
|
||||
|
||||
// 停止倒计时
|
||||
- (void)stopCountDown {
|
||||
if (self.timer != nil) {
|
||||
dispatch_source_cancel(self.timer);
|
||||
self.timer = nil;
|
||||
}
|
||||
self.isCountdownFinish = YES;
|
||||
}
|
||||
- (void)stopClockwise {
|
||||
if (self.clockwiseTimer != nil) {
|
||||
dispatch_source_cancel(self.clockwiseTimer);
|
||||
self.clockwiseTimer = nil;
|
||||
}
|
||||
self.isCountdownFinish = YES;
|
||||
}
|
||||
// 开始倒计时
|
||||
- (void)openCountdownWithTime:(int)totalTime{
|
||||
if (time <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
__block CGFloat time = (CGFloat)totalTime; //倒计时时间
|
||||
|
||||
if (self.timer != nil) {
|
||||
dispatch_source_cancel(self.timer);
|
||||
}
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
|
||||
dispatch_source_set_timer(self.timer,dispatch_walltime(NULL, 0),1*NSEC_PER_SEC, 0); //每秒执行
|
||||
__weak typeof(self) weakself = self;
|
||||
dispatch_source_set_event_handler(self.timer, ^{
|
||||
__strong typeof(weakself) self = weakself;
|
||||
if(time <= 0){ //倒计时结束,关闭
|
||||
dispatch_source_cancel(self.timer);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.isCountdownFinish = YES;
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(onCountdownFinish)]) {
|
||||
[self.delegate onCountdownFinish];
|
||||
|
||||
}
|
||||
});
|
||||
}else{
|
||||
time--;
|
||||
self.isCountdownFinish = NO;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
//设置按钮显示读秒效果
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(onCountdownOpen:)]) {
|
||||
[self.delegate onCountdownOpen:time];
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
dispatch_resume(self.timer);
|
||||
}
|
||||
|
||||
- (void)openClockwiseWithTime:(int)totalTime{
|
||||
if (totalTime <= 0) {
|
||||
return;
|
||||
}
|
||||
__block CGFloat backTime = 0; //倒计时时间
|
||||
if (self.clockwiseTimer != nil) {
|
||||
dispatch_source_cancel(self.clockwiseTimer);
|
||||
}
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
self.clockwiseTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
|
||||
dispatch_source_set_timer(self.clockwiseTimer,dispatch_walltime(NULL, 0),self.seconds*NSEC_PER_SEC, 0); //每秒执行
|
||||
__weak typeof(self) weakself = self;
|
||||
dispatch_source_set_event_handler(self.clockwiseTimer, ^{
|
||||
__strong typeof(weakself) self = weakself;
|
||||
if(backTime > totalTime){ //倒计时结束,关闭
|
||||
dispatch_source_cancel(self.clockwiseTimer);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.isCountdownFinish = YES;
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(onClockwiseFinish)]) {
|
||||
[self.delegate onClockwiseFinish];
|
||||
|
||||
}
|
||||
});
|
||||
}else{
|
||||
backTime = backTime + self.seconds;
|
||||
self.isCountdownFinish = NO;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
//设置按钮显示读秒效果
|
||||
|
||||
if(self.delegate && [self.delegate respondsToSelector:@selector(onClockwiseOpen:)]){
|
||||
[self.delegate onClockwiseOpen:backTime];
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
dispatch_resume(self.clockwiseTimer);
|
||||
}
|
||||
@end
|
Reference in New Issue
Block a user