JXShadeShowView.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // JXShadeShowView.m
  3. // shiku_im
  4. //
  5. // Created by os on 2020/7/11.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXShadeShowView.h"
  9. #import "SimpleAudioPlayer.h"
  10. @interface JXShadeShowView()<UIAlertViewDelegate>
  11. @property (nonatomic,weak) UIButton *knowBtn;
  12. @property (nonatomic,weak) UIImageView *imageV;
  13. @property (nonatomic,weak) UILabel *useName;
  14. @property (nonatomic,weak) UILabel *subTitle;
  15. @end
  16. @implementation JXShadeShowView
  17. -(instancetype)initWithFrame:(CGRect)frame{
  18. if (self=[super initWithFrame:frame]) {
  19. // self.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.9];
  20. UIImageView *backView=[[UIImageView alloc]init];
  21. backView.backgroundColor=[UIColor whiteColor];
  22. backView.layer.cornerRadius=60;
  23. backView.layer.masksToBounds=YES;
  24. [self addSubview:backView];
  25. self.imageV=backView;
  26. [backView mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.centerX.mas_equalTo(self.mas_centerX);
  28. make.top.mas_equalTo(JX_SCREEN_TOP+10);
  29. make.height.mas_equalTo(120);
  30. make.width.mas_equalTo(120);
  31. }];
  32. UILabel *titleLabel=[[UILabel alloc]init];
  33. titleLabel.text=@"用户名";
  34. titleLabel.textAlignment=NSTextAlignmentCenter;
  35. titleLabel.font=[UIFont systemFontOfSize:20 weight:UIFontWeightMedium];
  36. titleLabel.textColor=[UIColor whiteColor];
  37. [self addSubview:titleLabel];
  38. self.useName=titleLabel;
  39. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.top.mas_equalTo(backView.mas_bottom).mas_offset(30);
  41. make.centerX.mas_equalTo(backView.mas_centerX);
  42. }];
  43. UILabel *subTitle=[[UILabel alloc]init];
  44. subTitle.text=@"消息哪日";
  45. subTitle.textAlignment=NSTextAlignmentCenter;
  46. subTitle.font=[UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
  47. subTitle.numberOfLines=0;
  48. subTitle.textColor=[UIColor whiteColor];
  49. [self addSubview:subTitle];
  50. self.subTitle=subTitle;
  51. [subTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.centerX.mas_equalTo(titleLabel.mas_centerX);
  53. make.top.mas_equalTo(titleLabel.mas_bottom).mas_equalTo(20);
  54. make.left.mas_equalTo(30);
  55. make.right.mas_equalTo(-30);
  56. }];
  57. UIButton *knowBtn=[[UIButton alloc]init];
  58. knowBtn.titleLabel.font=[UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
  59. [knowBtn setTitle:@"忽略" forState:UIControlStateNormal];
  60. [self addSubview:knowBtn];
  61. self.knowBtn=knowBtn;
  62. [knowBtn addTarget:self action:@selector(closeBtnclick) forControlEvents:UIControlEventTouchUpInside];
  63. [knowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.mas_equalTo(100);
  65. make.bottom.mas_equalTo(-JX_SCREEN_TOP);
  66. }];
  67. UIButton *reciveBtn=[[UIButton alloc]init];
  68. reciveBtn.titleLabel.font=[UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
  69. [reciveBtn setTitle:@"接受" forState:UIControlStateNormal];
  70. reciveBtn.layer.masksToBounds=YES;
  71. [self addSubview:reciveBtn];
  72. [reciveBtn addTarget:self action:@selector(knowBtnclick) forControlEvents:UIControlEventTouchUpInside];
  73. [reciveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.right.mas_equalTo(-100);
  75. make.bottom.mas_equalTo(-JX_SCREEN_TOP);
  76. }];
  77. }
  78. return self;
  79. }
  80. - (void)setMessageObject:(JXMessageObject *)messageObject{
  81. _messageObject=messageObject;
  82. JXUserObject *userF = [[JXUserObject sharedInstance] getUserById:messageObject.fromUserId];
  83. [g_server delHeadImage:userF.userId];
  84. // dispatch_async(dispatch_get_main_queue(), ^{
  85. [g_server getHeadImageLarge:userF.userId userName:userF.userNickname imageView:_imageV];
  86. //});
  87. // 更新用户信息
  88. self.useName.text=userF.userNickname;
  89. self.subTitle.text=messageObject.content;
  90. }
  91. - (void)closeBtnclick{
  92. if (_cancelSoundBlock) {
  93. _cancelSoundBlock(_messageObject);
  94. }
  95. [SimpleAudioPlayer stopAllPlayers];
  96. [self removeFromSuperview];
  97. }
  98. - (void)knowBtnclick{
  99. [self removeFromSuperview];
  100. }
  101. -(void)setStrURL:(NSString *)strURL{
  102. self.subTitle.text=[NSString stringWithFormat:@"请添加微信号:%@,联系视频客服!",strURL];
  103. }
  104. - (void)thirdBtnAction {
  105. __block NSInteger second = 5;
  106. //(1)
  107. dispatch_queue_t quene = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  108. //(2)
  109. dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, quene);
  110. //(3)
  111. dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
  112. //(4)
  113. dispatch_source_set_event_handler(timer, ^{
  114. dispatch_async(dispatch_get_main_queue(), ^{
  115. if (second == 0) {
  116. //self.tongYiBtn.userInteractionEnabled = YES;
  117. //[self.tongYiBtn setTitle:[NSString stringWithFormat:@"5秒自动关闭"] forState:UIControlStateNormal];
  118. // second = 10;
  119. //(6)
  120. dispatch_cancel(timer);
  121. [self removeFromSuperview];
  122. } else {
  123. //self.tongYiBtn.userInteractionEnabled = NO;
  124. //[self.tongYiBtn setTitle:[NSString stringWithFormat:@"(%ld)秒自动关闭",(long)second] forState:UIControlStateNormal];
  125. second--;
  126. }
  127. });
  128. });
  129. //(5)
  130. dispatch_resume(timer);
  131. }
  132. +(void)showView{
  133. JXShadeShowView *show=[[JXShadeShowView alloc]init];
  134. show.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.98];
  135. show.frame=[UIScreen mainScreen].bounds;
  136. [[UIApplication sharedApplication].keyWindow addSubview:show];
  137. }
  138. @end