JXALLShowView.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 "JXALLShowView.h"
  9. @interface JXALLShowView()<UITextViewDelegate>
  10. @property (nonatomic,weak)UILabel *subtitle;
  11. @property (nonatomic,weak) JXALLShowView *show;
  12. @end
  13. @implementation JXALLShowView
  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);
  31. make.width.mas_equalTo(JX_SCREEN_WIDTH-100);
  32. }];
  33. UILabel *subtitle=[[UILabel alloc]init];
  34. subtitle.text=@"本活动奖励仅限每周六中午12点开放领取!";
  35. subtitle.textColor=[UIColor whiteColor];
  36. subtitle.textAlignment=NSTextAlignmentCenter;
  37. subtitle.numberOfLines=3;
  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(63);
  43. make.centerX.mas_equalTo(whiteShowView.mas_centerX);
  44. make.left.mas_equalTo(1);
  45. make.right.mas_equalTo(-1);
  46. }];
  47. UIButton *tongYiBtn=[[UIButton alloc]init];
  48. tongYiBtn.titleLabel.font=[UIFont systemFontOfSize:11 weight:UIFontWeightMedium];
  49. [tongYiBtn setTitle:@"5秒自动关闭" forState:UIControlStateNormal];
  50. [tongYiBtn setTitleColor:kRGBColor51 forState:UIControlStateNormal];
  51. [whiteShowView addSubview:tongYiBtn];
  52. self.tongYiBtn=tongYiBtn;
  53. [tongYiBtn addTarget:self action:@selector(tongyiBtn:) forControlEvents:UIControlEventTouchUpInside];
  54. [tongYiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.bottom.mas_equalTo(-3);
  56. make.centerX.mas_equalTo(whiteShowView.mas_centerX);
  57. }];
  58. [self thirdBtnAction];
  59. }
  60. return self;
  61. }
  62. - (void)thirdBtnAction {
  63. __block NSInteger second = 5;
  64. //(1)
  65. dispatch_queue_t quene = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  66. //(2)
  67. dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, quene);
  68. //(3)
  69. dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
  70. //(4)
  71. dispatch_source_set_event_handler(timer, ^{
  72. dispatch_async(dispatch_get_main_queue(), ^{
  73. if (second == 0) {
  74. self.tongYiBtn.userInteractionEnabled = YES;
  75. [self.tongYiBtn setTitle:[NSString stringWithFormat:@"5秒自动关闭"] forState:UIControlStateNormal];
  76. // second = 10;
  77. //(6)
  78. dispatch_cancel(timer);
  79. [self removeFromSuperview];
  80. } else {
  81. self.tongYiBtn.userInteractionEnabled = NO;
  82. [self.tongYiBtn setTitle:[NSString stringWithFormat:@"(%ld)秒自动关闭",(long)second] forState:UIControlStateNormal];
  83. second--;
  84. }
  85. });
  86. });
  87. //(5)
  88. dispatch_resume(timer);
  89. }
  90. +(void)showView{
  91. JXALLShowView *show=[[JXALLShowView alloc]init];
  92. show.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.2];
  93. show.frame=[UIScreen mainScreen].bounds;
  94. [[UIApplication sharedApplication].keyWindow addSubview:show];
  95. }
  96. -(void)setNameStr:(NSString *)nameStr{
  97. self.subtitle.text=nameStr.length>0?nameStr:@"本活动奖励仅限每周六中午12点开放领取!";
  98. }
  99. -(void)dissmisView{
  100. [self removeFromSuperview];
  101. }
  102. - (void)tongyiBtn:(UIButton *)sender{
  103. // [g_notify postNotificationName:@"comeBack" object:nil];
  104. //
  105. }
  106. @end