JXMeiRiShowView.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // JXMoneyShareView.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/6/22.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXMeiRiShowView.h"
  9. @interface JXMeiRiShowView()<UITextViewDelegate>
  10. @property (nonatomic,weak)UILabel *timeStr;
  11. @property (nonatomic,weak) JXMeiRiShowView *show;
  12. @end
  13. @implementation JXMeiRiShowView
  14. -(instancetype)initWithFrame:(CGRect)frame{
  15. if (self=[super initWithFrame:frame]) {
  16. UIView *backView=[[UIView alloc]init];
  17. backView.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.2];
  18. [self addSubview:backView];
  19. [backView mas_makeConstraints:^(MASConstraintMaker *make) {
  20. make.top.mas_equalTo(0);
  21. make.left.and.right.mas_equalTo(0);
  22. make.bottom.mas_equalTo(0);
  23. }];
  24. UIImageView *whiteShowView=[[UIImageView alloc]init];
  25. whiteShowView.image=[UIImage imageNamed:@"shareBackIMG"];
  26. whiteShowView.userInteractionEnabled=YES;
  27. [backView addSubview:whiteShowView];
  28. [whiteShowView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.centerX.mas_equalTo(backView.mas_centerX);
  30. make.centerY.mas_equalTo(backView.mas_centerY).mas_offset(10);
  31. make.width.mas_equalTo(JX_SCREEN_WIDTH-100);
  32. make.height.mas_equalTo(JX_SCREEN_WIDTH<414?160:150);
  33. }];
  34. UILabel *subtitle=[[UILabel alloc]init];
  35. subtitle.text=@" 恭喜您,您成功领取了今日任务奖励,赶紧去我的即信钱包查看。如果长时间未到账,请联系在线客服!";
  36. subtitle.textColor=[UIColor whiteColor];
  37. subtitle.numberOfLines=0;
  38. subtitle.font=[UIFont systemFontOfSize:13 weight:UIFontWeightMedium];
  39. [whiteShowView addSubview:subtitle];
  40. [subtitle mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.top.mas_equalTo(60);
  42. make.left.mas_equalTo(5);
  43. make.right.mas_equalTo(-5);
  44. make.centerX.mas_equalTo(whiteShowView.mas_centerX);
  45. }];
  46. UILabel *subtitle2=[[UILabel alloc]init];
  47. subtitle2.text=@"";
  48. subtitle2.textColor=[UIColor whiteColor];
  49. subtitle2.textAlignment=NSTextAlignmentCenter;
  50. subtitle2.font=[UIFont systemFontOfSize:13 weight:UIFontWeightMedium];
  51. [whiteShowView addSubview:subtitle2];
  52. [subtitle2 mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.top.mas_equalTo(subtitle.mas_bottom).mas_offset(1);
  54. make.centerX.mas_equalTo(whiteShowView.mas_centerX);
  55. }];
  56. UIButton *tongYiBtn=[[UIButton alloc]init];
  57. tongYiBtn.titleLabel.font=[UIFont systemFontOfSize:11 weight:UIFontWeightMedium];
  58. [tongYiBtn setTitle:@"5秒自动关闭" forState:UIControlStateNormal];
  59. [tongYiBtn setTitleColor:kRGBColor51 forState:UIControlStateNormal];
  60. [whiteShowView addSubview:tongYiBtn];
  61. self.tongYiBtn=tongYiBtn;
  62. [tongYiBtn addTarget:self action:@selector(tongyiBtn:) forControlEvents:UIControlEventTouchUpInside];
  63. [tongYiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.bottom.mas_equalTo(-10);
  65. make.centerX.mas_equalTo(whiteShowView.mas_centerX);
  66. }];
  67. [self thirdBtnAction];
  68. }
  69. return self;
  70. }
  71. - (void)thirdBtnAction {
  72. __block NSInteger second = 5;
  73. //(1)
  74. dispatch_queue_t quene = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  75. //(2)
  76. dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, quene);
  77. //(3)
  78. dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
  79. //(4)
  80. dispatch_source_set_event_handler(timer, ^{
  81. dispatch_async(dispatch_get_main_queue(), ^{
  82. if (second == 0) {
  83. self.tongYiBtn.userInteractionEnabled = YES;
  84. [self.tongYiBtn setTitle:[NSString stringWithFormat:@"5秒自动关闭"] forState:UIControlStateNormal];
  85. // second = 10;
  86. //(6)
  87. dispatch_cancel(timer);
  88. [self removeFromSuperview];
  89. } else {
  90. self.tongYiBtn.userInteractionEnabled = NO;
  91. [self.tongYiBtn setTitle:[NSString stringWithFormat:@"(%ld)秒自动关闭",(long)second] forState:UIControlStateNormal];
  92. second--;
  93. }
  94. });
  95. });
  96. //(5)
  97. dispatch_resume(timer);
  98. }
  99. +(void)showView{
  100. JXMeiRiShowView *show=[[JXMeiRiShowView alloc]init];
  101. show.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.2];
  102. show.frame=[UIScreen mainScreen].bounds;
  103. [[UIApplication sharedApplication].keyWindow addSubview:show];
  104. }
  105. -(void)dissmisView{
  106. [self removeFromSuperview];
  107. }
  108. - (void)tongyiBtn:(UIButton *)sender{
  109. // [g_notify postNotificationName:@"comeBack" object:nil];
  110. //
  111. }
  112. @end