SignSuccessPopView.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // SignSuccessPopView.m
  3. // BuguLive
  4. //
  5. // Created by bugu on 2019/11/29.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "SignSuccessPopView.h"
  9. @interface SignSuccessPopView ()
  10. //@property(nonatomic, strong) UIView *bgView;
  11. //@property(nonatomic, strong) UIButton *tipButton;
  12. @property(nonatomic, strong) UIImageView *bgImageView;
  13. @property(nonatomic, strong) UILabel *titleLabel;
  14. @property(nonatomic, strong) UILabel *giftLabel;
  15. @property(nonatomic, strong) UIImageView *successImageView;
  16. @property(nonatomic, strong) UIButton *closeButton;
  17. @property(nonatomic, strong) NSString *gift;
  18. @property(nonatomic, strong) dismissBlock block;
  19. @end
  20. static NSString *const image_name_bg = @"签到成功背景";
  21. static NSString *const image_name_success = @"签到成功";
  22. static NSString *const image_name_btn = @"签到成功按钮";
  23. @implementation SignSuccessPopView
  24. +(void)showSignSuccessViewGift:(NSString *)gift WithComplete:(dismissBlock)complete{
  25. SignSuccessPopView *view=[[SignSuccessPopView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  26. view.gift = gift;
  27. view.block = complete;
  28. [view pop];
  29. }
  30. - (void)setGift:(NSString *)gift{
  31. _gift = gift;
  32. _giftLabel.text = [NSString stringWithFormat:ASLocalizedString(@"恭喜获得%@个钻石"),gift];
  33. }
  34. - (instancetype)initWithFrame:(CGRect)frame {
  35. self = [super initWithFrame:frame];
  36. if (self) {
  37. [self initUI];
  38. }
  39. return self;
  40. }
  41. - (void)initUI {
  42. // self.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.4];
  43. _bgImageView = ({
  44. UIImageView * iv = [[UIImageView alloc] init];
  45. iv.image = [UIImage imageNamed:image_name_bg];
  46. iv.userInteractionEnabled = YES;
  47. iv;
  48. });
  49. _titleLabel = ({
  50. UILabel * label = [[UILabel alloc]init];
  51. label.textColor = kWhiteColor;
  52. label.font = [UIFont boldSystemFontOfSize:22];
  53. label.text = ASLocalizedString(@"签到成功");
  54. label;
  55. });
  56. _giftLabel = ({
  57. UILabel * label = [[UILabel alloc]init];
  58. label.textColor = kWhiteColor;
  59. label.font = [UIFont systemFontOfSize:14];
  60. label.numberOfLines = 0;
  61. label.text = @"";
  62. label;
  63. });
  64. _successImageView = ({
  65. UIImageView * iv = [[UIImageView alloc] init];
  66. iv.image = [UIImage imageNamed:image_name_success];
  67. iv;
  68. });
  69. _closeButton = ({
  70. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  71. [btn setBackgroundImage:[UIImage imageNamed:image_name_btn] forState:UIControlStateNormal];
  72. [btn setTitle:ASLocalizedString(@"知道啦")forState:UIControlStateNormal];
  73. [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  74. btn.titleLabel.font = [UIFont systemFontOfSize:14];
  75. [btn addTarget:self action:@selector(dismissAction) forControlEvents:UIControlEventTouchUpInside];
  76. btn;
  77. });
  78. [self addSubview:_bgImageView];
  79. [_bgImageView addSubview:_titleLabel];
  80. [_bgImageView addSubview:_giftLabel];
  81. [_bgImageView addSubview:_successImageView];
  82. [_bgImageView addSubview:_closeButton];
  83. }
  84. - (void)dismissAction{
  85. [self dismiss];
  86. !self.block?:self.block();
  87. }
  88. - (void)layoutSubviews {
  89. [super layoutSubviews];
  90. [_bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  91. // make.top.mas_equalTo(187);
  92. make.centerX.mas_equalTo(0);
  93. make.centerY.mas_equalTo(0);
  94. }];
  95. [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.top.mas_equalTo(31);
  97. make.centerX.mas_equalTo(0);
  98. }];
  99. [_giftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.top.mas_equalTo(64);
  101. // make.centerX.mas_equalTo(0);
  102. make.right.equalTo(_bgImageView).offset(-5);
  103. make.left.equalTo(_bgImageView).offset(5);
  104. }];
  105. [_closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.bottom.mas_equalTo(-20);
  107. make.centerX.mas_equalTo(0);
  108. }];
  109. [_successImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.bottom.mas_equalTo(-70);
  111. make.centerX.mas_equalTo(0);
  112. }];
  113. }
  114. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  115. UITouch *touch = [touches anyObject];
  116. if ([touch.view isEqual:self]) {
  117. [self dismiss];
  118. }
  119. }
  120. -(void)pop
  121. {
  122. UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
  123. [keyWindow addSubview:self];
  124. self.bgImageView.transform = CGAffineTransformMakeScale(0.1, 0.1);
  125. [UIView animateWithDuration:0.3 animations:^{
  126. self.bgImageView.transform = CGAffineTransformIdentity;
  127. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
  128. }];
  129. }
  130. -(void)dismiss
  131. {
  132. [UIView animateWithDuration:0.3 animations:^{
  133. self.bgImageView.transform = CGAffineTransformMakeScale(0.1, 0.1);
  134. } completion:^(BOOL finished) {
  135. [self removeFromSuperview];
  136. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
  137. }];
  138. }
  139. @end