MORedEntranceView.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // MORedEntranceView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/6/17.
  6. //
  7. #import "MORedEntranceView.h"
  8. @interface MORedEntranceView ()
  9. @property (weak, nonatomic) IBOutlet UIView *bgView;
  10. @property (weak, nonatomic) IBOutlet UILabel *timeLab;
  11. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *numberLabelWidth;
  12. @property (weak, nonatomic) IBOutlet UILabel *numLab;
  13. @property (weak, nonatomic) IBOutlet UIImageView *avatarView;
  14. @property (nonatomic, strong) MORedEnvelopesInfo *firstObject;
  15. @end
  16. @implementation MORedEntranceView
  17. + (instancetype)moRedEntranceView{
  18. return [[[NSBundle mainBundle] loadNibNamed:@"MORedEntranceView" owner:self options:nil] firstObject];
  19. }
  20. - (void)awakeFromNib{
  21. [super awakeFromNib];
  22. self.bgView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.2];
  23. self.bgView.layer.cornerRadius = 9;
  24. self.bgView.layer.masksToBounds = YES;
  25. self.timeLab.layer.cornerRadius = 10.0 / 2.0;
  26. self.timeLab.layer.masksToBounds = YES;
  27. self.numLab.backgroundColor = [MOTools colorWithHexString:@"#FF4A50"];
  28. self.numLab.font = [MOTextTools getTheFontWithSize:10.0 AndFontName:kNormalContentFontStr];
  29. self.numLab.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
  30. self.numLab.layer.cornerRadius = 14.0 / 2.0;
  31. self.numLab.layer.masksToBounds = YES;
  32. self.avatarView.layer.masksToBounds = YES;
  33. self.avatarView.layer.cornerRadius = 15.0 / 2.0;
  34. self.avatarView.layer.borderColor = [MOTools colorWithHexString:@"#FEF9BA"].CGColor;
  35. self.avatarView.layer.borderWidth = 1;
  36. }
  37. - (void)showAnimation {
  38. // 初始状态
  39. self.transform = CGAffineTransformConcat(
  40. CGAffineTransformMakeTranslation(-self.bounds.size.width * 0.5, self.bounds.size.height * 0.5),
  41. CGAffineTransformMakeScale(0.3, 0.3)
  42. );
  43. self.alpha = 0.0;
  44. self.numLab.transform = CGAffineTransformMakeTranslation(30, 0);
  45. self.numLab.alpha = 0.0;
  46. // 动画过程
  47. [UIView animateWithDuration:0.5
  48. delay:0
  49. options:UIViewAnimationOptionCurveEaseOut
  50. animations:^{
  51. self.transform = CGAffineTransformIdentity;
  52. self.alpha = 1.0;
  53. } completion:^(BOOL finished) {
  54. [UIView animateWithDuration:0.25 animations:^{
  55. self.numLab.transform = CGAffineTransformIdentity;
  56. self.numLab.alpha = 1.0;
  57. }];
  58. }];
  59. }
  60. - (IBAction)openRedBtnClick:(id)sender {
  61. self.openRedBlock ? self.openRedBlock() : nil;
  62. }
  63. - (void)setRedData:(MORedEnvelopesListData *)redData{
  64. _redData = redData;
  65. if(redData.redEnvelopesInfo.count > 0){
  66. NSArray *sortedArray = [redData.redEnvelopesInfo sortedArrayUsingDescriptors:@[
  67. [NSSortDescriptor sortDescriptorWithKey:@"startTime" ascending:YES]
  68. ]];
  69. self.firstObject = sortedArray.firstObject;
  70. self.numLab.hidden = NO;
  71. NSString *numberString = [NSString stringWithFormat:@"%zd", redData.redEnvelopesInfo.count];
  72. CGFloat numberWidth = numberString.length * 10;
  73. if (numberWidth < 14) {
  74. numberWidth = 14;
  75. }
  76. self.numLab.text = numberString;
  77. self.numberLabelWidth.constant = numberWidth;
  78. [self.avatarView sd_setImageWithURL:[NSURL URLWithString:self.firstObject.userAvatar]];
  79. }
  80. else{
  81. self.numLab.text = @"0";
  82. self.numLab.hidden = YES;
  83. }
  84. [self updateTheTimeText];
  85. }
  86. - (void)updateTheTimeText{
  87. NSTimeInterval time = 0;
  88. NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970] * 1000;
  89. //大于开始时间
  90. if((self.firstObject.startTime - (round(currentTime) - GetRedSysTime)) < 0){
  91. self.timeLab.text = @"00:00";
  92. self.timeLab.hidden = YES;
  93. }
  94. else{
  95. time = round((self.firstObject.startTime - (round(currentTime) - GetRedSysTime)) / 1000);
  96. NSString *timeStr = [NSDate formattedTimeStringFromTimeInterval:time AndFormatStr:@"mm:ss"];
  97. self.timeLab.text = timeStr;
  98. self.timeLab.hidden = NO;
  99. }
  100. }
  101. @end