// // JXGoldShowView.m // shiku_im // // Created by os on 2020/6/24. // Copyright © 2020 Reese. All rights reserved. // #import "JXGoldShowView.h" @interface JXGoldShowView() @property (nonatomic,weak)UILabel *subTitle; @property (nonatomic,weak) JXGoldShowView *show; @property (nonatomic,weak) UIButton *tongYiBtn; @end @implementation JXGoldShowView -(instancetype)initWithFrame:(CGRect)frame{ if (self=[super initWithFrame:frame]) { UIView *backView=[[UIView alloc]init]; backView.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.2]; [self addSubview:backView]; [backView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.and.right.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; UIImageView *whiteShowView=[[UIImageView alloc]init]; whiteShowView.image=[UIImage imageNamed:@"shareBackIMG"]; whiteShowView.userInteractionEnabled=YES; [backView addSubview:whiteShowView]; [whiteShowView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(backView.mas_centerX); make.centerY.mas_equalTo(backView.mas_centerY); //make.left.mas_equalTo(20); //make.right.mas_equalTo(-20); }]; UILabel *subtitle=[[UILabel alloc]init]; subtitle.text=@"您已成功提交奖励申请,"; subtitle.textColor=[UIColor whiteColor]; subtitle.font=[UIFont systemFontOfSize:13 weight:UIFontWeightMedium]; [whiteShowView addSubview:subtitle]; self.subTitle=subtitle; [subtitle mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(60); make.centerX.mas_equalTo(whiteShowView.mas_centerX); }]; UILabel *subtitle2=[[UILabel alloc]init]; subtitle2.text=@"请耐心等待"; subtitle2.textColor=[UIColor whiteColor]; subtitle2.textAlignment=NSTextAlignmentCenter; subtitle2.font=[UIFont systemFontOfSize:13 weight:UIFontWeightMedium]; [whiteShowView addSubview:subtitle2]; [subtitle2 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(subtitle.mas_bottom).mas_offset(1); make.centerX.mas_equalTo(whiteShowView.mas_centerX); }]; UIButton *tongYiBtn=[[UIButton alloc]init]; tongYiBtn.titleLabel.font=[UIFont systemFontOfSize:11 weight:UIFontWeightMedium]; [tongYiBtn setTitle:@"5秒自动关闭" forState:UIControlStateNormal]; [tongYiBtn setTitleColor:kRGBColor51 forState:UIControlStateNormal]; [whiteShowView addSubview:tongYiBtn]; self.tongYiBtn=tongYiBtn; [tongYiBtn addTarget:self action:@selector(tongyiBtn:) forControlEvents:UIControlEventTouchUpInside]; [tongYiBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(-10); make.centerX.mas_equalTo(whiteShowView.mas_centerX); }]; [self thirdBtnAction]; } return self; } - (void)thirdBtnAction { __block NSInteger second = 5; //(1) dispatch_queue_t quene = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); //(2) dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, quene); //(3) dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0 * NSEC_PER_SEC); //(4) dispatch_source_set_event_handler(timer, ^{ dispatch_async(dispatch_get_main_queue(), ^{ if (second == 0) { self.tongYiBtn.userInteractionEnabled = YES; [self.tongYiBtn setTitle:[NSString stringWithFormat:@"5秒自动关闭"] forState:UIControlStateNormal]; // second = 10; //(6) dispatch_cancel(timer); [self removeFromSuperview]; } else { self.tongYiBtn.userInteractionEnabled = NO; [self.tongYiBtn setTitle:[NSString stringWithFormat:@"(%ld)秒自动关闭",(long)second] forState:UIControlStateNormal]; second--; } }); }); //(5) dispatch_resume(timer); } +(void)showView{ JXGoldShowView *show=[[JXGoldShowView alloc]init]; show.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.2]; show.frame=[UIScreen mainScreen].bounds; [[UIApplication sharedApplication].keyWindow addSubview:show]; } -(void)dissmisView{ [self removeFromSuperview]; } - (void)tongyiBtn:(UIButton *)sender{ // [g_notify postNotificationName:@"comeBack" object:nil]; // } @end