| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- //
- // MONewComerGiftView.m
- // MiMoLive
- //
- // Created by MiMo on 2025/6/8.
- //
- #import "MONewComerGiftView.h"
- #import "UILabel+MOBezierAnimation.h"
- #import "MOUserGift.h"
- @interface MONewComerGiftItemView ()
- @property (nonatomic, strong) UIView *backgroundView;
- @property (nonatomic, strong) UIImageView *iconImgView;
- @property (nonatomic, strong) UILabel *amountLabel;
- @property (nonatomic, strong) UILabel *nameLabel;
- @end
- @implementation MONewComerGiftItemView
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- [self setupUI];
- }
- return self;
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
-
- [self.backgroundView setupGradientLayerWithView:self.backgroundView
- startColor:[MOTools colorWithHexString:@"#FFFBFD"]
- endColor:[MOTools colorWithHexString:@"#FFE4F2"]
- layerName:@"gradientLayer"
- startPoint:(CGPoint) { 0.5, 0 }
- endPoint:(CGPoint){0.5, 1}];
- }
- - (void)setGiftModel:(MOUserGift *)giftModel {
- _giftModel = giftModel;
-
- [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:giftModel.image]];
-
- self.nameLabel.text = [NSString stringWithFormat:@"%@", giftModel.name];
-
- NSString *amountText = nil;
- if (giftModel.type == 1) {//钻石 *num
- amountText = [NSString stringWithFormat:@"* %zd", giftModel.amount];
- self.nameLabel.hidden = YES;
- [self.amountLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.backgroundView.mas_bottom).offset(2);
- make.left.right.mas_equalTo(0);
- make.height.mas_equalTo(20);
- }];
-
- } else if (giftModel.type == 2) {//礼物 *num
- amountText = [NSString stringWithFormat:@"* %zd", giftModel.amount];
- } else if (giftModel.type == 3) {//道具 *d
- amountText = [NSString stringWithFormat:@"* %zdd", giftModel.amount];
- } else if (giftModel.type == 4) {//勋章 *d
- amountText = [NSString stringWithFormat:@"* %zdd", giftModel.amount];
- }
- self.amountLabel.text = amountText;
- }
- - (void)setupUI {
-
- [self addSubview:self.backgroundView];
- [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(0);
- make.centerX.mas_equalTo(0);
- make.width.mas_equalTo(71);
- make.height.mas_equalTo(71);
- }];
-
- [self addSubview:self.iconImgView];
- [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self.backgroundView);
- make.width.mas_equalTo(43);
- make.height.mas_equalTo(43);
- }];
-
- [self addSubview:self.nameLabel];
- [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.backgroundView.mas_bottom).offset(2);
- make.left.right.mas_equalTo(0);
- make.height.mas_equalTo(20);
- }];
-
- [self addSubview:self.amountLabel];
- [self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.nameLabel.mas_bottom);
- make.left.right.mas_equalTo(0);
- make.height.mas_equalTo(20);
- }];
- }
- - (UIView *)backgroundView {
- if (!_backgroundView) {
- _backgroundView = [[UIView alloc] init];
- _backgroundView.layer.masksToBounds = YES;
- _backgroundView.layer.borderColor = [MOTools colorWithHexString:@"#FFA2D1"].CGColor;
- _backgroundView.layer.borderWidth = 1;
- _backgroundView.layer.cornerRadius = 9;
- }
- return _backgroundView;
- }
- - (UIImageView *)iconImgView {
- if (!_iconImgView) {
- _iconImgView = [[UIImageView alloc] init];
- _iconImgView.contentMode = UIViewContentModeScaleAspectFill;
- }
- return _iconImgView;
- }
- - (UILabel *)amountLabel {
- if (!_amountLabel) {
- _amountLabel = [[UILabel alloc] init];
- _amountLabel.font = [MOTextTools mediumFont:13];
- _amountLabel.textColor = kBaseTextColor_2;
- _amountLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _amountLabel;
- }
- - (UILabel *)nameLabel {
- if (!_nameLabel) {
- _nameLabel = [[UILabel alloc] init];
- _nameLabel.font = [MOTextTools mediumFont:13];
- _nameLabel.textColor = kBaseTextColor_2;
- _nameLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _nameLabel;
- }
- @end
- #define kMONewComerGiftViewWidth 297
- #define kMOActivityRewardViewHeight 393
- #import "MONewComerGiftView.h"
- @interface MONewComerGiftView ()
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, strong) UIImageView *bgImgView;
- @property (nonatomic, strong) UIImageView *giftIconView;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UILabel *descLabel;
- @property (nonatomic, strong) UIView *contentView;
- @property (nonatomic, strong) UIButton *getButton;
- @property (nonatomic, strong) UIButton *closeButton;
- @end
- @implementation MONewComerGiftView
- - (instancetype)init {
- if (self = [super init]) {
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI {
- [self addSubview:self.bgView];
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
-
- [self addSubview:self.bgImgView];
- [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(0);
- make.centerY.mas_equalTo(-25);
- make.size.mas_equalTo(CGSizeMake(kMONewComerGiftViewWidth, kMOActivityRewardViewHeight));
- }];
-
- [self.bgImgView addSubview:self.giftIconView];
- [self.giftIconView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgImgView).offset(-26);
- make.right.equalTo(self.bgImgView);
- make.size.mas_equalTo(CGSizeMake(101, 103));
- }];
-
- [self.bgImgView addSubview:self.titleLabel];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(16);
- make.top.mas_equalTo(14);
- make.right.mas_equalTo(-110);
- }];
-
- [self.bgImgView addSubview:self.descLabel];
- [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(16);
- make.top.equalTo(self.titleLabel.mas_bottom);
- make.right.mas_equalTo(-90);
- }];
-
- [self.bgImgView addSubview:self.contentView];
- [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(68);
- make.left.mas_equalTo(13);
- make.right.mas_equalTo(-13);
- make.bottom.mas_equalTo(-69);
- }];
-
- [self.bgImgView addSubview:self.getButton];
- [self.getButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(0);
- make.width.mas_equalTo(255);
- make.height.mas_equalTo(44);
- make.bottom.mas_equalTo(-15);
- }];
-
- [self addSubview:self.closeButton];
- [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.bgImgView.mas_bottom).offset(17);
- make.centerX.mas_equalTo(0);
- make.size.mas_equalTo(CGSizeMake(32, 32));
- }];
-
- [self setNeedsLayout];
- [self layoutIfNeeded];
-
- [self.titleLabel setGradientWithColors:@[(id)[MOTools colorWithHexString:@"#FF4DA6" alpha:1.0].CGColor,(id)[MOTools colorWithHexString:@"#4363FF" alpha:1.0].CGColor] startPoint:CGPointMake(0.0, 0.0) endPoint:CGPointMake(1.0, 0.0)];
- [self.contentView setupGradientLayerWithView:self.contentView
- startColor:[MOTools colorWithHexString:@"#FFFFFF" alpha:0.5]
- endColor:[MOTools colorWithHexString:@"#FFFFFF" alpha:0.8]
- layerName:@"gradientLayer"
- startPoint:(CGPoint) { 0.5, 0 }
- endPoint:(CGPoint){0.5, 1}];
- }
- - (void)setModel:(MODialogsData *)model {
- _model = model;
-
- [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
- NSArray *dataList = model.userGifts;
-
- NSInteger count = dataList.count;
- if (count == 0) return;
- CGFloat topPadding = 12;
- CGFloat headPadding = 8;//相邻item上下间距固定8
- CGFloat leftPadding = (count > 4 && count <= 6) ? 12 : 19;
- CGFloat interItemSpacing = (count > 4 && count <= 6) ? 18 : 15;//相邻item左右间距
- CGFloat itemWidth = (count > 4 && count <= 6) ? 71 : 110;
- CGFloat itemHeight = 112;
- NSInteger numberOfColumns = (count > 4 && count <= 6) ? 3 : 2;
- for (NSInteger i = 0; i < count; i++) {
- NSInteger row = i / numberOfColumns;
- NSInteger column = i % numberOfColumns;
- CGFloat x = column == 0 ? leftPadding : (leftPadding + column * (itemWidth + interItemSpacing));
- CGFloat y = topPadding + row * (itemHeight + headPadding);
-
- MONewComerGiftItemView *itemView = [[MONewComerGiftItemView alloc] initWithFrame:CGRectMake(x, y, itemWidth, itemHeight)];
- itemView.giftModel = dataList[i];
- [self.contentView addSubview:itemView];
- }
-
- }
- - (void)getBtnAction {
- if (self.getBlock) {
- self.getBlock();
- }
- [self dismiss];
- }
- - (void)show {
- UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
- [keyWindow addSubview:self];
- self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
-
- //动画效果
- self.bgImgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
- self.bgImgView.alpha = 0;
- [UIView animateWithDuration:0.2 animations:^ {
- self.bgImgView.transform = CGAffineTransformMakeScale(1.0, 1.0);
- self.bgImgView.alpha = 1;
- } completion:nil];
- }
- - (void)dismiss {
- [UIView animateWithDuration:0.2 animations:^ {
- self.bgImgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
- self.bgImgView.alpha = 0;
- } completion:^(BOOL finished) {
- if (finished) {
- [self removeFromSuperview];
- if (self.dismissBlock) {
- self.dismissBlock();
- }
- }
- }];
- }
- - (UIView *)bgView {
- if (!_bgView) {
- _bgView = [[UIView alloc] init];
- _bgView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.5];
- // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
- // [_bgView addGestureRecognizer:tap];
- }
- return _bgView;
- }
- - (UIImageView *)bgImgView {
- if (!_bgImgView) {
- _bgImgView = [[UIImageView alloc] init];
- _bgImgView.contentMode = UIViewContentModeScaleAspectFill;
- _bgImgView.image = [UIImage imageNamed:@"image_new_comer_gift_bg"];
- _bgImgView.userInteractionEnabled = YES;
- }
- return _bgImgView;
- }
- - (UIImageView *)giftIconView {
- if (!_giftIconView) {
- _giftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_new_user_gift"]];
- }
- return _giftIconView;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.text = NSLocalString(@"mimo_2_new_user_gift_title");
- _titleLabel.font = [MOTextTools poppinsExtraBoldFont:17];
- _titleLabel.numberOfLines = 1;
- _titleLabel.adjustsFontSizeToFitWidth = YES;
- }
- return _titleLabel;
- }
- - (UILabel *)descLabel {
- if (!_descLabel) {
- _descLabel = [[UILabel alloc] init];
- _descLabel.text = NSLocalString(@"mimo_2_new_user_gift_desc");
- _descLabel.font = [MOTextTools regularFont:12];
- _descLabel.textColor = kBaseTextColor_3;
- _descLabel.numberOfLines = 1;
- _descLabel.adjustsFontSizeToFitWidth = YES;
- }
- return _descLabel;
- }
- - (UIView *)contentView {
- if (!_contentView) {
- _contentView = [[UIView alloc] init];
- _contentView.layer.masksToBounds = YES;
- _contentView.layer.cornerRadius = 12;
- }
- return _contentView;
- }
- - (UIButton *)getButton {
- if (!_getButton) {
- _getButton = [[UIButton alloc] init];
- NSArray *colorArr = @[kBaseColorLeft,kBaseColorRight];
- UIImage *colorImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 255, 44.0) Colors:colorArr GradientType:0];
- [_getButton setBackgroundImage:colorImage forState:UIControlStateNormal];
- _getButton.layer.cornerRadius = 12;
- _getButton.layer.masksToBounds = YES;
- [_getButton setTitle:NSLocalString(@"mimo_2_new_user_gift_get") forState:UIControlStateNormal];
- [_getButton setTitleColor:[MOTools colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
- _getButton.titleLabel.font = [MOTextTools poppinsMediumFont:16];
- [_getButton addTarget:self action:@selector(getBtnAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _getButton;
- }
- - (UIButton *)closeButton {
- if (!_closeButton) {
- _closeButton = [[UIButton alloc] init];
- [_closeButton setImage:[UIImage imageNamed:@"icon_close_circle_white"] forState:UIControlStateNormal];
- [_closeButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
- }
- return _closeButton;
- }
- @end
|