// // JXShadeShowView.m // shiku_im // // Created by os on 2020/7/11. // Copyright © 2020 Reese. All rights reserved. // #import "JXShadeShowView.h" #import "SimpleAudioPlayer.h" @interface JXShadeShowView() @property (nonatomic,weak) UIButton *knowBtn; @property (nonatomic,weak) UIImageView *imageV; @property (nonatomic,weak) UILabel *useName; @property (nonatomic,weak) UILabel *subTitle; @end @implementation JXShadeShowView -(instancetype)initWithFrame:(CGRect)frame{ if (self=[super initWithFrame:frame]) { // self.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.9]; UIImageView *backView=[[UIImageView alloc]init]; backView.backgroundColor=[UIColor whiteColor]; backView.layer.cornerRadius=60; backView.layer.masksToBounds=YES; [self addSubview:backView]; self.imageV=backView; [backView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self.mas_centerX); make.top.mas_equalTo(JX_SCREEN_TOP+10); make.height.mas_equalTo(120); make.width.mas_equalTo(120); }]; UILabel *titleLabel=[[UILabel alloc]init]; titleLabel.text=@"用户名"; titleLabel.textAlignment=NSTextAlignmentCenter; titleLabel.font=[UIFont systemFontOfSize:20 weight:UIFontWeightMedium]; titleLabel.textColor=[UIColor whiteColor]; [self addSubview:titleLabel]; self.useName=titleLabel; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(backView.mas_bottom).mas_offset(30); make.centerX.mas_equalTo(backView.mas_centerX); }]; UILabel *subTitle=[[UILabel alloc]init]; subTitle.text=@"消息哪日"; subTitle.textAlignment=NSTextAlignmentCenter; subTitle.font=[UIFont systemFontOfSize:20 weight:UIFontWeightRegular]; subTitle.numberOfLines=0; subTitle.textColor=[UIColor whiteColor]; [self addSubview:subTitle]; self.subTitle=subTitle; [subTitle mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(titleLabel.mas_centerX); make.top.mas_equalTo(titleLabel.mas_bottom).mas_equalTo(20); make.left.mas_equalTo(30); make.right.mas_equalTo(-30); }]; UIButton *knowBtn=[[UIButton alloc]init]; knowBtn.titleLabel.font=[UIFont systemFontOfSize:16 weight:UIFontWeightRegular]; [knowBtn setTitle:@"忽略" forState:UIControlStateNormal]; [self addSubview:knowBtn]; self.knowBtn=knowBtn; [knowBtn addTarget:self action:@selector(closeBtnclick) forControlEvents:UIControlEventTouchUpInside]; [knowBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(100); make.bottom.mas_equalTo(-JX_SCREEN_TOP); }]; UIButton *reciveBtn=[[UIButton alloc]init]; reciveBtn.titleLabel.font=[UIFont systemFontOfSize:16 weight:UIFontWeightRegular]; [reciveBtn setTitle:@"接受" forState:UIControlStateNormal]; reciveBtn.layer.masksToBounds=YES; [self addSubview:reciveBtn]; [reciveBtn addTarget:self action:@selector(knowBtnclick) forControlEvents:UIControlEventTouchUpInside]; [reciveBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-100); make.bottom.mas_equalTo(-JX_SCREEN_TOP); }]; } return self; } - (void)setMessageObject:(JXMessageObject *)messageObject{ _messageObject=messageObject; JXUserObject *userF = [[JXUserObject sharedInstance] getUserById:messageObject.fromUserId]; [g_server delHeadImage:userF.userId]; // dispatch_async(dispatch_get_main_queue(), ^{ [g_server getHeadImageLarge:userF.userId userName:userF.userNickname imageView:_imageV]; //}); // 更新用户信息 self.useName.text=userF.userNickname; self.subTitle.text=messageObject.content; } - (void)closeBtnclick{ if (_cancelSoundBlock) { _cancelSoundBlock(_messageObject); } [SimpleAudioPlayer stopAllPlayers]; [self removeFromSuperview]; } - (void)knowBtnclick{ [self removeFromSuperview]; } -(void)setStrURL:(NSString *)strURL{ self.subTitle.text=[NSString stringWithFormat:@"请添加微信号:%@,联系视频客服!",strURL]; } - (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{ JXShadeShowView *show=[[JXShadeShowView alloc]init]; show.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.98]; show.frame=[UIScreen mainScreen].bounds; [[UIApplication sharedApplication].keyWindow addSubview:show]; } @end