// // JXMoneyShareView.m // shiku_im // // Created by 123 on 2020/6/22. // Copyright © 2020 Reese. All rights reserved. // #import "JXMeiRiShowView.h" @interface JXMeiRiShowView() @property (nonatomic,weak)UILabel *timeStr; @property (nonatomic,weak) JXMeiRiShowView *show; @end @implementation JXMeiRiShowView -(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).mas_offset(10); make.width.mas_equalTo(JX_SCREEN_WIDTH-100); make.height.mas_equalTo(JX_SCREEN_WIDTH<414?160:150); }]; UILabel *subtitle=[[UILabel alloc]init]; subtitle.text=@" 恭喜您,您成功领取了今日任务奖励,赶紧去我的即信钱包查看。如果长时间未到账,请联系在线客服!"; subtitle.textColor=[UIColor whiteColor]; subtitle.numberOfLines=0; subtitle.font=[UIFont systemFontOfSize:13 weight:UIFontWeightMedium]; [whiteShowView addSubview:subtitle]; [subtitle mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(60); make.left.mas_equalTo(5); make.right.mas_equalTo(-5); 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{ JXMeiRiShowView *show=[[JXMeiRiShowView 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