| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- //
- // MORedEntranceView.m
- // MiMoLive
- //
- // Created by SuperC on 2024/6/17.
- //
- #import "MORedEntranceView.h"
- @interface MORedEntranceView ()
- @property (weak, nonatomic) IBOutlet UIView *bgView;
- @property (weak, nonatomic) IBOutlet UILabel *timeLab;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *numberLabelWidth;
- @property (weak, nonatomic) IBOutlet UILabel *numLab;
- @property (weak, nonatomic) IBOutlet UIImageView *avatarView;
- @property (nonatomic, strong) MORedEnvelopesInfo *firstObject;
- @end
- @implementation MORedEntranceView
- + (instancetype)moRedEntranceView{
- return [[[NSBundle mainBundle] loadNibNamed:@"MORedEntranceView" owner:self options:nil] firstObject];
- }
- - (void)awakeFromNib{
- [super awakeFromNib];
-
- self.bgView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.2];
- self.bgView.layer.cornerRadius = 9;
- self.bgView.layer.masksToBounds = YES;
-
-
- self.timeLab.layer.cornerRadius = 10.0 / 2.0;
- self.timeLab.layer.masksToBounds = YES;
-
- self.numLab.backgroundColor = [MOTools colorWithHexString:@"#FF4A50"];
- self.numLab.font = [MOTextTools getTheFontWithSize:10.0 AndFontName:kNormalContentFontStr];
- self.numLab.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
- self.numLab.layer.cornerRadius = 14.0 / 2.0;
- self.numLab.layer.masksToBounds = YES;
-
- self.avatarView.layer.masksToBounds = YES;
- self.avatarView.layer.cornerRadius = 15.0 / 2.0;
- self.avatarView.layer.borderColor = [MOTools colorWithHexString:@"#FEF9BA"].CGColor;
- self.avatarView.layer.borderWidth = 1;
- }
- - (void)showAnimation {
- // 初始状态
- self.transform = CGAffineTransformConcat(
- CGAffineTransformMakeTranslation(-self.bounds.size.width * 0.5, self.bounds.size.height * 0.5),
- CGAffineTransformMakeScale(0.3, 0.3)
- );
- self.alpha = 0.0;
-
- self.numLab.transform = CGAffineTransformMakeTranslation(30, 0);
- self.numLab.alpha = 0.0;
- // 动画过程
- [UIView animateWithDuration:0.5
- delay:0
- options:UIViewAnimationOptionCurveEaseOut
- animations:^{
- self.transform = CGAffineTransformIdentity;
- self.alpha = 1.0;
- } completion:^(BOOL finished) {
- [UIView animateWithDuration:0.25 animations:^{
- self.numLab.transform = CGAffineTransformIdentity;
- self.numLab.alpha = 1.0;
- }];
- }];
- }
- - (IBAction)openRedBtnClick:(id)sender {
- self.openRedBlock ? self.openRedBlock() : nil;
- }
- - (void)setRedData:(MORedEnvelopesListData *)redData{
- _redData = redData;
-
-
- if(redData.redEnvelopesInfo.count > 0){
- NSArray *sortedArray = [redData.redEnvelopesInfo sortedArrayUsingDescriptors:@[
- [NSSortDescriptor sortDescriptorWithKey:@"startTime" ascending:YES]
- ]];
- self.firstObject = sortedArray.firstObject;
-
- self.numLab.hidden = NO;
- NSString *numberString = [NSString stringWithFormat:@"%zd", redData.redEnvelopesInfo.count];
- CGFloat numberWidth = numberString.length * 10;
- if (numberWidth < 14) {
- numberWidth = 14;
- }
- self.numLab.text = numberString;
- self.numberLabelWidth.constant = numberWidth;
-
- [self.avatarView sd_setImageWithURL:[NSURL URLWithString:self.firstObject.userAvatar]];
- }
- else{
- self.numLab.text = @"0";
- self.numLab.hidden = YES;
- }
-
- [self updateTheTimeText];
- }
- - (void)updateTheTimeText{
- NSTimeInterval time = 0;
- NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970] * 1000;
-
- //大于开始时间
- if((self.firstObject.startTime - (round(currentTime) - GetRedSysTime)) < 0){
- self.timeLab.text = @"00:00";
- self.timeLab.hidden = YES;
- }
- else{
- time = round((self.firstObject.startTime - (round(currentTime) - GetRedSysTime)) / 1000);
- NSString *timeStr = [NSDate formattedTimeStringFromTimeInterval:time AndFormatStr:@"mm:ss"];
- self.timeLab.text = timeStr;
- self.timeLab.hidden = NO;
- }
-
- }
- @end
|