XYRotarytableWinningView.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // XYRotarytableWinningView.m
  3. // Timi
  4. //
  5. // Created by 翟玉磊 on 2021/4/19.
  6. //
  7. #import "XYRotarytableWinningView.h"
  8. @interface XYRotarytableWinningView ()
  9. @property (nonatomic, strong) UIView *infoView;
  10. @property (nonatomic, strong) UIImageView *bgImageView;
  11. @property (nonatomic, strong) UIImageView *textBgImageView;
  12. @property (nonatomic, strong) UILabel *textLabel;
  13. @end
  14. @implementation XYRotarytableWinningView
  15. #pragma mark — Public
  16. - (void)clear {
  17. for (UIView *view in self.subviews) {
  18. [view removeFromSuperview];
  19. }
  20. }
  21. - (void)startAnimationWithText:(NSString *)text {
  22. self.textLabel.text = text;
  23. [self startAnimation];
  24. }
  25. - (void)startAnimation {
  26. [UIView animateWithDuration:.3 animations:^{
  27. self.infoView.frame = CGRectMake(self.infoView.f_x, 0, self.infoView.f_width, self.infoView.f_width);
  28. } completion:^(BOOL finished) {
  29. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  30. [self endAnimation];
  31. });
  32. }];
  33. }
  34. - (void)endAnimation {
  35. [UIView animateWithDuration:.3 animations:^{
  36. self.infoView.frame = CGRectMake(self.infoView.f_x, self.infoView.f_width, self.infoView.f_width, self.infoView.f_width);
  37. } completion:^(BOOL finished) {
  38. [self clear];
  39. }];
  40. }
  41. - (instancetype)initWithFrame:(CGRect)frame
  42. {
  43. self = [super initWithFrame:frame];
  44. if (self) {
  45. [self setupUI];
  46. }
  47. return self;
  48. }
  49. - (void)setupUI {
  50. self.backgroundColor = Color_Clear;
  51. [self addSubview:self.infoView];
  52. [self.infoView addSubview:self.bgImageView];
  53. [self.infoView addSubview:self.textBgImageView];
  54. [self.infoView addSubview:self.textLabel];
  55. }
  56. #pragma mark — Getter
  57. - (UIView *)infoView {
  58. if (!_infoView) {
  59. CGFloat width = self.f_width - 50.0f - 50.0f;
  60. CGFloat height = 44.0f;
  61. _infoView = [[UIView alloc] initWithFrame:CGRectMake(50.0f, -height, width, height)];
  62. _infoView.backgroundColor = Color_Clear;
  63. }
  64. return _infoView;
  65. }
  66. - (UIImageView *)bgImageView {
  67. if (!_bgImageView) {
  68. _bgImageView = [[UIImageView alloc] initWithFrame:self.infoView.bounds];
  69. _bgImageView.backgroundColor = [UIColor colorGradientChangeWithSize:CGSizeMake(_bgImageView.f_width, _bgImageView.f_heigh) direction:GradientChangeDirectionVertical startColor:ColorFromHexString(@"#FA5DDB") endColor:ColorFromHexString(@"#7C7EFE")];
  70. [_bgImageView addViewBorder:Color_Clear redian:5];
  71. }
  72. return _bgImageView;
  73. }
  74. - (UIImageView *)textBgImageView {
  75. if (!_textBgImageView) {
  76. CGFloat width = self.bgImageView.f_width - 7.0f - 7.0f;
  77. CGFloat height = self.bgImageView.f_heigh - 7.0f - 7.0f;
  78. _textBgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(7.0f, 7.0f, width, height)];
  79. _textBgImageView.backgroundColor = [UIColor colorGradientChangeWithSize:CGSizeMake(width, height) direction:GradientChangeDirectionVertical startColor:ColorFromHexString(@"#AA24F8") endColor:ColorFromHexString(@"#6460FF")];
  80. [_textBgImageView addViewBorder:Color_Clear redian:5];
  81. }
  82. return _textBgImageView;
  83. }
  84. - (UILabel *)textLabel {
  85. if (!_textLabel) {
  86. _textLabel = [UILabel createLabelTextColor:Color_White fount:Font(13)];
  87. _textLabel.textAlignment = NSTextAlignmentCenter;
  88. _textLabel.frame = CGRectMake(14.0f, 14.0f, self.infoView.f_width - 14.0f - 14.0f, 16.0f);
  89. }
  90. return _textLabel;
  91. }
  92. @end