123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- //
- // LFWCountDownView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/1/17.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LFWCountDownView.h"
- #define TimerFont [UIFont systemFontOfSize:13]
- @interface LFWCountDownView (){
- NSUInteger expiresTime;
- NSUInteger nowTime;
- NSDate *date1970;
- NSDateFormatter *dateFormatter;
- NSUInteger lastSeconds;
- NSInteger aDay;
- }
- @property (nonatomic, strong) dispatch_source_t timer;
- /**小时*/
- @property (nonatomic,strong) UIButton *hourBtn;
- @property (nonatomic,strong) UIButton *hourBtn2;
- /**分钟*/
- @property (nonatomic,strong) UIButton *minuteBtn;
- @property (nonatomic,strong) UIButton *minuteBtn2;
- /**秒*/
- @property (nonatomic,strong) UIButton *secondBtn;
- @property (nonatomic,strong) UIButton *secondBtn2;
- /**:*/
- @property (nonatomic,strong) UIButton *textBtn;
- @property (nonatomic,strong) UIButton *textBtn1;
- @property (nonatomic,strong) UIButton *textBtn2;
- @property (nonatomic,strong) UIButton *textBtn3;
- @end
- static LFWCountDownView *_countDownView = nil;
- @implementation LFWCountDownView
- + (instancetype)shareInstace {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- _countDownView = [[LFWCountDownView alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];
- });
- return _countDownView;
- }
- - (instancetype)initWithFrame:(CGRect)frame andEndTimer:(NSString *)endTimer
- {
- NSDate *date = [NSDate date];
- NSTimeInterval timeinterval =[date timeIntervalSince1970];
- NSTimeInterval endTime = timeinterval + endTimer.longLongValue;
-
- // NSString *timeString2 = [NSString stringWithFormat:@"%.0f", a2];
-
- expiresTime = endTime;
- return [self initWithFrame:frame];
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- date1970 = [NSDate dateWithTimeIntervalSince1970:0];
- dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"HH mm ss"];
- aDay = 86399;
- expiresTime = 0;
- nowTime = 0;
-
-
-
- [self addSubview:self.textBtn];
- [self addSubview:self.hourBtn];
- [self addSubview:self.hourBtn2];
- [self addSubview:self.textBtn1];
- [self addSubview:self.minuteBtn];
- [self addSubview:self.minuteBtn2];
- [self addSubview:self.textBtn2];
- [self addSubview:self.secondBtn];
- [self addSubview:self.secondBtn2];
- [self addSubview:self.textBtn3];
-
- }
- return self;
- }
- - (void)countDown {
- // 从1970年到现在的时间(秒)
- NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
- NSTimeInterval second =[dat timeIntervalSince1970];
- NSString *starTimer = [NSString stringWithFormat:@"%.0f", second];
-
- nowTime = starTimer.longLongValue;
-
- __block NSUInteger timeout= expiresTime; //倒计时时间
- NSString *curStr = [self homeLimitTimeString];
- [self labelValueHandler:curStr];
-
- if (_timer) {
- dispatch_source_cancel(_timer);
- }
-
- dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
- dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1*NSEC_PER_SEC, 0); //每秒执行
- dispatch_source_set_event_handler(_timer, ^{
- if(timeout<=starTimer.longLongValue){ //倒计时结束,关闭
- dispatch_source_cancel(_timer);
- dispatch_async(dispatch_get_main_queue(), ^{
-
- });
- if (self.delegate && [self.delegate respondsToSelector:@selector(countViewTimeOutAction)]) {
- [self.delegate countViewTimeOutAction];
- }
- }else{
- NSString *curStr1 = [self homeLimitTimeString];
- dispatch_async(dispatch_get_main_queue(), ^{
- [self labelValueHandler:curStr1];
- });
-
- timeout--;
- }
- });
- dispatch_resume(_timer);
- }
- - (void)setEndTimer:(NSString *)endTimer {
-
- NSDate *date = [NSDate date];
- NSTimeInterval timeinterval =[date timeIntervalSince1970];
- NSString *endTimeStr = [NSString stringWithFormat:@"%.0f",timeinterval];
- NSTimeInterval endTime = endTimeStr.longLongValue + endTimer.longLongValue/1000;
-
- expiresTime = endTime; //到期的时间戳
-
- // NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
- // NSTimeInterval second =[dat timeIntervalSince1970];
- // NSString *starTimer = [NSString stringWithFormat:@"%.0f", second];
- // nowTime = starTimer.longLongValue;
- [self countDown];
- }
- -(NSString*)homeLimitTimeString{
-
- NSTimeInterval timeActualValue;
- if (expiresTime<nowTime) {
- return @"00 00 00";
- }
- NSTimeInterval diffTime = expiresTime - nowTime;
- // NSLog(@"%ld",(expiresTime - nowTime)/3600/24); /// 这里可以设置天数
- timeActualValue = diffTime;
- nowTime++;
-
- NSDate *curDate = [date1970 dateByAddingTimeInterval:timeActualValue];
- NSTimeZone *zone = [NSTimeZone timeZoneWithAbbreviation:@"GMT-0800"];
- NSInteger interval = [zone secondsFromGMTForDate: curDate];
- NSDate *localeDate = [curDate dateByAddingTimeInterval: interval];
- NSString *destDateString = [dateFormatter stringFromDate:localeDate];
-
- return destDateString;
- }
- -(void)labelValueHandler:(NSString*)text{
- NSArray *titleArr = [text componentsSeparatedByString:@" "];
- NSString *hourStr = titleArr[0];
- NSString *minStr = titleArr[1];
- NSString *secondStr = titleArr[2];
-
- [self.hourBtn setTitle:[hourStr substringWithRange:NSMakeRange(0, 1)] forState:UIControlStateNormal];
- [self.hourBtn2 setTitle:[hourStr substringWithRange:NSMakeRange(1, 1)] forState:UIControlStateNormal];
-
- [self.minuteBtn setTitle:[minStr substringWithRange:NSMakeRange(0, 1)] forState:UIControlStateNormal];
- [self.minuteBtn2 setTitle:[minStr substringWithRange:NSMakeRange(1, 1)] forState:UIControlStateNormal];
-
- [self.secondBtn setTitle:[secondStr substringWithRange:NSMakeRange(0, 1)] forState:UIControlStateNormal];
- [self.secondBtn2 setTitle:[secondStr substringWithRange:NSMakeRange(1, 1)] forState:UIControlStateNormal];
- }
- #pragma mark =============== layzer ==================
- - (UIButton *)textBtn
- {
- if (_textBtn == nil) {
- _textBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _textBtn.frame = CGRectMake(0, 0, 50, self.frame.size.height);
- _textBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
- [_textBtn setTitle:@"距更新" forState:UIControlStateNormal];
- _textBtn.titleLabel.font = [UIFont systemFontOfSize:12];
- [_textBtn setTitleColor:[UIColor YHColorWithHex:0x999999] forState:UIControlStateNormal];
- }
- return _textBtn;
- }
- - (UIButton *)hourBtn
- {
- if (_hourBtn == nil) {
- _hourBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _hourBtn.frame = CGRectMake(CGRectGetMaxX(_textBtn.frame), 0, 12, self.frame.size.height);
- _hourBtn.backgroundColor = [UIColor YHColorWithHex:0x444444];
- _hourBtn.titleLabel.font = TimerFont;
- _hourBtn.layer.cornerRadius = 3;
- }
- return _hourBtn;
- }
- - (UIButton *)hourBtn2
- {
- if (_hourBtn2 == nil) {
- _hourBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
- _hourBtn2.frame = CGRectMake(CGRectGetMaxX(_hourBtn.frame)+2, 0, 12, self.frame.size.height);
- _hourBtn2.backgroundColor = [UIColor YHColorWithHex:0x444444];
- _hourBtn2.titleLabel.font = TimerFont;
- _hourBtn2.layer.cornerRadius = 3;
- }
- return _hourBtn2;
- }
- - (UIButton *)textBtn1
- {
- if (_textBtn1 == nil) {
- _textBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
- _textBtn1.frame = CGRectMake(CGRectGetMaxX(_hourBtn2.frame), 0, 20, _hourBtn.frame.size.height);
- _textBtn1.titleLabel.textAlignment = NSTextAlignmentCenter;
- [_textBtn1 setTitle:@"时" forState:UIControlStateNormal];
- _textBtn1.titleLabel.font = [UIFont systemFontOfSize:12];
- [_textBtn1 setTitleColor:[UIColor YHColorWithHex:0x999999] forState:UIControlStateNormal];
- }
- return _textBtn1;
- }
- - (UIButton *)minuteBtn
- {
- if (_minuteBtn == nil) {
- _minuteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _minuteBtn.frame = CGRectMake(CGRectGetMaxX(_textBtn1.frame),0 , 12, _hourBtn.frame.size.height);
- _minuteBtn.titleLabel.font = TimerFont;
- _minuteBtn.backgroundColor = [UIColor YHColorWithHex:0x444444];
- _minuteBtn.layer.cornerRadius = 3;
- }
- return _minuteBtn;
- }
- - (UIButton *)minuteBtn2
- {
- if (_minuteBtn2 == nil) {
- _minuteBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
- _minuteBtn2.frame = CGRectMake(CGRectGetMaxX(_minuteBtn.frame)+2,0 , 12, _hourBtn.frame.size.height);
- _minuteBtn2.titleLabel.font = TimerFont;
- _minuteBtn2.backgroundColor = [UIColor YHColorWithHex:0x444444];
- _minuteBtn2.layer.cornerRadius = 3;
- }
- return _minuteBtn2;
- }
- - (UIButton *)textBtn2
- {
- if (_textBtn2 == nil) {
- _textBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
- _textBtn2.frame = CGRectMake(CGRectGetMaxX(_minuteBtn2.frame), 0, 20, _hourBtn.frame.size.height);
- _textBtn2.titleLabel.textAlignment = NSTextAlignmentCenter;
- [_textBtn2 setTitle:@"分" forState:UIControlStateNormal];
- _textBtn2.titleLabel.font = [UIFont systemFontOfSize:12];
- [_textBtn2 setTitleColor:[UIColor YHColorWithHex:0x999999] forState:UIControlStateNormal];
- }
- return _textBtn2;
- }
- - (UIButton *)secondBtn
- {
- if (_secondBtn == nil) {
- _secondBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _secondBtn.frame = CGRectMake(CGRectGetMaxX(_textBtn2.frame), 0, 12,_hourBtn.frame.size.height);
- _secondBtn.backgroundColor = [UIColor YHColorWithHex:0x444444];
- _secondBtn.titleLabel.font = TimerFont;
- _secondBtn.layer.cornerRadius = 3;
-
- }
- return _secondBtn;
- }
- - (UIButton *)secondBtn2
- {
- if (_secondBtn2 == nil) {
- _secondBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
- _secondBtn2.frame = CGRectMake(CGRectGetMaxX(_secondBtn.frame)+2, 0, 12,_hourBtn.frame.size.height);
- _secondBtn2.backgroundColor = [UIColor YHColorWithHex:0x444444];
- _secondBtn2.titleLabel.font = TimerFont;
- _secondBtn2.layer.cornerRadius = 3;
-
- }
- return _secondBtn2;
- }
- - (UIButton *)textBtn3
- {
- if (_textBtn3 == nil) {
- _textBtn3 = [UIButton buttonWithType:UIButtonTypeCustom];
- _textBtn3.frame = CGRectMake(CGRectGetMaxX(_secondBtn2.frame), 0, 20, _hourBtn.frame.size.height);
- _textBtn3.titleLabel.textAlignment = NSTextAlignmentCenter;
- [_textBtn3 setTitle:@"秒" forState:UIControlStateNormal];
- _textBtn3.titleLabel.font = [UIFont systemFontOfSize:12];
- [_textBtn3 setTitleColor:[UIColor YHColorWithHex:0x999999] forState:UIControlStateNormal];
- }
- return _textBtn3;
- }
- -(void)ah7tOFq:(UIApplication*) ah7tOFq acisnf:(UIBarButtonItem*) acisnf aJ0kpAO4q:(UIAlertView*) aJ0kpAO4q and2X0:(UIRegion*) and2X0 a2Zxn6Fc:(UIImage*) a2Zxn6Fc aVRHXj:(UIBezierPath*) aVRHXj aprd2KB7ew:(UIScreen*) aprd2KB7ew aXZni6:(UIMenuItem*) aXZni6 a1Qjx:(UIBarButtonItem*) a1Qjx ahn6WAFp:(UIBarButtonItem*) ahn6WAFp akhR5XxWL0S:(UISwitch*) akhR5XxWL0S afmRzWPT:(UIBezierPath*) afmRzWPT aB9lFh0Zep1:(UIScreen*) aB9lFh0Zep1 a70AOM2NgT8:(UIMenuItem*) a70AOM2NgT8 aBVlQw:(UIApplication*) aBVlQw {
- NSLog(@"H6uFAdBz0mw8refjoDCYs9cKWqx");
- NSLog(@"HiSawD1t9mlj5oWpLQ3s");
- NSLog(@"WNRcMpmSA29HE7ZLT3w1vDC5dkeQbuy");
- NSLog(@"kLIejSZrnai0Ru");
- NSLog(@"AKGR1Ivfr9CdDjM8Uknw0EQT73");
- NSLog(@"QlW2oirIk0OY");
- NSLog(@"RG6faqeQEJANplorygOT37kLD5KC1stj42cd");
- NSLog(@"Eex1056jaPckshmogBbIZ3vY2OwK7utr");
- NSLog(@"HL4pZdU3Kl0kjOnwuGJcDE9Wx8hPa756fAoIQmT");
- NSLog(@"F4bPTM2XxVgqRA7H");
- NSLog(@"5mprvPXxTcaLHQhyCNEuoifGIYj4ZVqRnF9");
- NSLog(@"35yXbDWtHshS4VmeIKZRrdA89T");
- NSLog(@"V8m0sNqUxtn67bQEGM3fXRK2");
- NSLog(@"oiBIQDYkluVh6WKwTft1rHZPJLgMR8besay");
- NSLog(@"7tuI3Kkfqp5xVnW2GQvjCYB");
- NSLog(@"XvwD1bEqP4M6Wi");
- NSLog(@"rtQzXj4LSsucay1IhUCf7PqgTpiA2MB8ROv");
- NSLog(@"ku3eNCETApzt6QbsVKYoGwqnHB2d5JljyRcxW");
- NSLog(@"lqCRXJPmfIYLtUch5HyKnN1Mj");
- NSLog(@"7oJtNwLSGFnIOvE");
- }
- -(void)alRB5grzT3H:(UIImageView*) alRB5grzT3H a1zMk0j:(UIAlertView*) a1zMk0j aKGXnpC:(UILabel*) aKGXnpC aMfPhd9O14:(UIImage*) aMfPhd9O14 atZNrb:(UIImageView*) atZNrb adCuBxp:(UIImageView*) adCuBxp aX8fEC2SVPI:(UIUserInterfaceIdiom*) aX8fEC2SVPI a5AaNyGT6:(UIFontWeight*) a5AaNyGT6 aSHtyO:(UILabel*) aSHtyO aQk48:(UISearchBar*) aQk48 avrIB:(UIViewController*) avrIB aDfxkHKS:(UIColor*) aDfxkHKS au2w94H:(UIWindow*) au2w94H aAF2CxQOWT:(UIControl*) aAF2CxQOWT al12Wfr:(UIView*) al12Wfr aSjrxdgQpP5:(UIWindow*) aSjrxdgQpP5 aUAR3vfs:(UISwitch*) aUAR3vfs aCeQUmLFax7:(UIControlEvents*) aCeQUmLFax7 aq0QziB7t82:(UIRegion*) aq0QziB7t82 apUbaWhLJ:(UIVisualEffectView*) apUbaWhLJ {
- NSLog(@"qHSW5LxnBzRb0ZO1tT42DUydpmGM9f8");
- NSLog(@"A6f1yMoWuE5mjVS90TJd3NiqtU");
- NSLog(@"nAE3yljTiC7JHt9zm");
- NSLog(@"y8Q9EV4mNutj1XhdrFfKxGv0M");
- NSLog(@"PQstHwErNpbd5IiLzcVq20v8uJ");
- NSLog(@"9U26seLT501NC3at");
- NSLog(@"425UZCxO9zkVwgjMvEcbiBLf8Po3");
- NSLog(@"bvBUFYdiRrm2uo4PL9gM0l1GXhWtpcO78jVySz");
- NSLog(@"EbIC5pWOYq6tTAn1");
- NSLog(@"mpUlyCGwEjnhzIWTKaf2");
- NSLog(@"haWlILe8COYio6HNUKbXjBu");
- NSLog(@"xvwHqV3jBFeptYP0M8TU5uyDhO6Jld");
- NSLog(@"Y4cFL9KpHgxN856y2BqG0");
- NSLog(@"8VXqJKWH9G");
- NSLog(@"kQXO6ETgyqAP5uBjZWtxMfSdbwLCVHz93Upin");
- NSLog(@"ebya0QEZwWPMnIKVi");
- NSLog(@"F1zVjmk7Gx34XcnsI0NwPTCp");
- NSLog(@"Nk3QJKiB7dvsRLrjWg2bH8VPFAmEDYUup1co");
- NSLog(@"Gr9Szfmpg1evA0xdPHTKoO");
- NSLog(@"tjx8bZHMSByq4sw56deEUKi7");
- }
- -(void)afPzq:(UISearchBar*) afPzq at7I2wgTv:(UISearchBar*) at7I2wgTv a9LJ57Y:(UISwitch*) a9LJ57Y aeXJFQHTs2V:(UIAlertView*) aeXJFQHTs2V a8s6irxwAp:(UIMenuItem*) a8s6irxwAp aEDe9IQRZ:(UIKeyCommand*) aEDe9IQRZ aZPM42:(UIScreen*) aZPM42 aReqad:(UIActivity*) aReqad amg13pZF5X:(UIUserInterfaceIdiom*) amg13pZF5X a4oephD:(UIControl*) a4oephD a5HMmBITE:(UIDevice*) a5HMmBITE anAWle647x:(UIWindow*) anAWle647x ae2a74Xyd:(UIBezierPath*) ae2a74Xyd aDpRASfi7:(UIEvent*) aDpRASfi7 aRpy5oTFv1H:(UIControl*) aRpy5oTFv1H at4MiwRvCX:(UIDevice*) at4MiwRvCX aHzM4YprDOZ:(UIMenuItem*) aHzM4YprDOZ {
- NSLog(@"5XbIDZKJc4W2Gnw1uj9yCFAxozMaRt");
- NSLog(@"86TtR51aPwKbmYqBXFvHDkQIrd4yN9ZOE7uJx2Mh");
- NSLog(@"2D9yCZWsKIArn1BtczS8obLQqMYhJOa5X");
- NSLog(@"lhYSyLC7Vdn03bzDJE8Qx");
- NSLog(@"SwEGz1sg4JROM673cpiLtv85ZoWqXuINb9hFrkP");
- NSLog(@"czQWeFR80Hnp");
- NSLog(@"60NYV7rdDSymJaoMz");
- NSLog(@"06r4BxIgP8yMASELp5H");
- NSLog(@"YF2aI49KmL5qJVtc6");
- NSLog(@"p7Y8jaMsQ2XD4d9goR6vzkAyBG5SUe");
- NSLog(@"zknIBDZxsWu0");
- NSLog(@"2rSeE67kvOyDIdNpnGC93KPH");
- NSLog(@"Z4TONqJaQCGBbwo92tH6v");
- NSLog(@"z9VASCEtL630XkF");
- NSLog(@"9m7AgaZyeCE2Kxp5qcOBzGX3j0bilU");
- NSLog(@"Ac4g09ifLrwMyBRhabvHTsz2JOUpm8NkYloS1tXI");
- NSLog(@"Mh5YKSyQrcEU");
- NSLog(@"PbZXQYDWOMdewv7iraVtlU3");
- }
- -(void)aEAB0w:(UICollectionView*) aEAB0w aPOuJExz:(UIControlEvents*) aPOuJExz aJgDpGO:(UIDevice*) aJgDpGO aLNkPb:(UICollectionView*) aLNkPb a1mqPXt0CE:(UIControl*) a1mqPXt0CE aAepdW:(UIViewController*) aAepdW aVQKnNv:(UIViewController*) aVQKnNv aUNgnxX:(UIControl*) aUNgnxX aUpZB79WwR:(UIActivity*) aUpZB79WwR aTRZeO8vpq7:(UIFontWeight*) aTRZeO8vpq7 arSexX4AnhI:(UIBezierPath*) arSexX4AnhI aVO4MJzuRC:(UIColor*) aVO4MJzuRC aSWODMN7sl:(UIColor*) aSWODMN7sl ajo3SDV6KZC:(UIRegion*) ajo3SDV6KZC aWGQICB:(UIButton*) aWGQICB aWz0M:(UIInputView*) aWz0M {
- NSLog(@"sOzxDSHiKkcFhraWLI6UEQMPnN85ZJy0");
- NSLog(@"6ux7pNmKYGWLMS");
- NSLog(@"oPjpLUmN8X");
- NSLog(@"wxbdnHJDAB5689zX3GICUfyVN");
- NSLog(@"G3geCo298adQhPrpujHIwM");
- NSLog(@"u9LGc38PCmRSJrswNeEYAd0MU6tkn4vbZQpx1");
- NSLog(@"ION7K9zjwuPfBn6siX");
- NSLog(@"yPlEJ0TY2wCItGFA7rWfVXi4Ko68bqBd");
- NSLog(@"k24G7ZhgCdTo1eYMyPu");
- NSLog(@"l6Abcq3VBoEj8LHXDChK2Zk9rFgSvztaiyUfG0m");
- NSLog(@"sPup0yCJDkzAcnwUhZlYLIjHB9WKEQ");
- NSLog(@"fw6N0VpKjgMsYDzxX5ScEIOaomJk");
- NSLog(@"3HdJ5PyUhl9O");
- NSLog(@"v3KFDQNtb64slAqR7OIjXM8pSTn");
- }
- @end
|