// // MOClickNumView.m // MiMoLive // // Created by SuperC on 2024/4/26. // #import "MOClickNumView.h" #import "UILabel+MOBezierAnimation.h" @implementation MOClickNumView - (instancetype)init { if (self = [super init]) { [self setupUI]; } return self; } - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setupUI]; } return self; } - (void)setupUI{ [self addSubview:self.zuanImgView]; [self.zuanImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self).offset(15); make.centerY.equalTo(self).offset(3.0); make.width.height.equalTo(@30.0); }]; [self addSubview:self.numLab]; [self.numLab mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self).offset(-15.0); make.centerY.equalTo(self); make.height.equalTo(@30.0); make.width.greaterThanOrEqualTo(@30.0); }]; } - (UIImageView *)zuanImgView{ if(!_zuanImgView){ _zuanImgView = [[UIImageView alloc] init]; [_zuanImgView setImage:[UIImage imageNamed:@"icon_click_zuan"]]; _zuanImgView.contentMode = UIViewContentModeScaleAspectFit; } return _zuanImgView; } - (UILabel *)numLab { if(!_numLab) { _numLab = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 100, 30.0)]; _numLab.textColor = UIColorFromHex(0xFFFFFF); UIFont *customFont = [UIFont fontWithName:kNormalGiftNumFontStre size:MOClickNumViewFont]; if(customFont){ _numLab.font = customFont; } else{ _numLab.font = [UIFont italicSystemFontOfSize:MOClickNumViewFont]; } _numLab.textAlignment = NSTextAlignmentRight; _numLab.backgroundColor = [UIColor clearColor]; _numLab.text = @"1"; } return _numLab; } - (void)showViewWith:(UIView *)superView ShowNum:(NSInteger)num isGetZuan:(BOOL)isShowZuan{ [superView addSubview:self]; self.numLab.text = [NSString stringWithFormat:@"x%zd",num]; if(isShowZuan){ self.zuanImgView.hidden = NO; self.numLab.text = [NSString stringWithFormat:@"x%zd",num]; // self.numLab.textColor = [MOTools colorWithHexString:@"#E72DD3" alpha:1.0]; [self.numLab setGradientWithColors: @[(id)[MOTools colorWithHexString:@"#FFE76C" alpha:1.0].CGColor,(id)[MOTools colorWithHexString:@"#FF7519" alpha:1.0].CGColor] startPoint:CGPointMake(0.0, 0.3) endPoint:CGPointMake(0.0, 1.0)]; [self.numLab mas_updateConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self).offset(-15.0); }]; [self.layer addSublayer:self.numLab.layer]; [self.layer addSublayer:self.zuanImgView.layer]; self.transform = CGAffineTransformMakeScale(0.6, 0.6); self.alpha = 0; [UIView animateWithDuration:0.2 animations:^ { self.transform = CGAffineTransformMakeScale(1.0, 1.0); self.alpha = 1; } completion:^(BOOL finished) { [self zuanDismiiView]; }]; } else{ self.zuanImgView.hidden = YES; // self.numLab.textColor = [UIColor whiteColor]; [self.numLab setGradientWithColors: @[(id)[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0].CGColor,(id)[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0].CGColor] startPoint:CGPointMake(0.0, 0.3) endPoint:CGPointMake(0.0, 1.0)]; [self.numLab mas_updateConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self).offset(0.0); }]; [self.layer addSublayer:self.numLab.layer]; [self.layer addSublayer:self.zuanImgView.layer]; self.transform = CGAffineTransformMakeScale(1.4, 1.4); self.alpha = 0; [UIView animateWithDuration:0.2 animations:^ { self.transform = CGAffineTransformMakeScale(1.0, 1.0); self.alpha = 1; } completion:^(BOOL finished) { [self dismissView]; }]; } } - (void)dismissView{ [UIView animateWithDuration:1.0 animations:^{ self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y - 50, self.frame.size.width, self.frame.size.height); self.transform = CGAffineTransformScale(self.transform, 0.2, 0.2); self.alpha = 0.0; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } - (void)zuanDismiiView{ [UIView animateWithDuration:1.0 animations:^{ self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y - 50, self.frame.size.width, self.frame.size.height); self.transform = CGAffineTransformScale(self.transform, 1.2, 1.2); self.alpha = 0.0; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } @end