JXGoldShowView.m 4.7 KB

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