// // QXMineAddSongView.m // QXLive // // Created by 启星 on 2025/11/13. // #import "QXMineAddSongView.h" @interface QXMineAddSongView() @property (nonatomic,strong)UIView *bgView; @property (nonatomic,strong)UILabel *titleLabel; @property (nonatomic,strong)UIButton *closeBtn; @property (nonatomic,strong)UIView *songContenView; @property (nonatomic,strong)UITextField *songTextField; @property (nonatomic,strong)UIView *giftContenView; @property (nonatomic,strong)UILabel *giftLabel; @property (nonatomic,strong)UIImageView *giftArrow; @property (nonatomic,strong)UIButton *giftBtn; @property (nonatomic,strong)UIButton *cancelBtn; @property (nonatomic,strong)UIButton *commitBtn; @end @implementation QXMineAddSongView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } -(void)setGiftModel:(QXGiftModel *)giftModel{ _giftModel = giftModel; self.giftLabel.text = [NSString stringWithFormat:@"%@x%@",giftModel.gift_name,giftModel.num]; if (self.songModel) { self.songModel.gift_num = giftModel.num; self.songModel.gift_id = giftModel.gift_id; } } -(void)setSongModel:(QXUserSongListModel *)songModel{ _songModel = songModel; self.giftLabel.text = [NSString stringWithFormat:@"%@x%@",songModel.gift_name,songModel.gift_num]; self.songTextField.text = songModel.song_name; } -(void)initSubviews{ self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3]; self.bgView = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-ScaleWidth(275))/2, 0, ScaleWidth(275), 300)]; self.bgView.backgroundColor = RGB16(0xffffff); [self.bgView addRoundedCornersWithRadius:16]; [self addSubview:self.bgView]; self.titleLabel = [[UILabel alloc] init]; self.titleLabel.text = @"新增歌单"; self.titleLabel.font = [UIFont boldSystemFontOfSize:16]; self.titleLabel.textColor = QXConfig.textColor; [self.bgView addSubview:self.titleLabel]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.bgView); make.top.equalTo(self.bgView).offset(12); make.height.mas_equalTo(24); }]; self.closeBtn = [[UIButton alloc] init]; [self.closeBtn setImage:[UIImage imageNamed:@"wallet_close"] forState:(UIControlStateNormal)]; [self.closeBtn addTarget:self action:@selector(hide) forControlEvents:(UIControlEventTouchUpInside)]; [self.bgView addSubview:self.closeBtn]; [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.bgView); make.height.width.mas_equalTo(40); make.centerY.equalTo(self.titleLabel); }]; self.songContenView = [[UIView alloc] init]; [self.songContenView addRoundedCornersWithRadius:11]; self.songContenView.backgroundColor = RGB16(0xEFF2F8); [self.bgView addSubview:self.songContenView]; [self.songContenView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.right.mas_equalTo(-10); make.height.mas_equalTo(41); make.top.equalTo(self.titleLabel.mas_bottom).offset(36); }]; self.songTextField = [[UITextField alloc] init]; self.songTextField.font = [UIFont systemFontOfSize:16]; self.songTextField.textColor = RGB16(0x9B9B9B); self.songTextField.delegate = self; self.songTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入歌曲名称" attributes:@{NSForegroundColorAttributeName:RGB16(0x9B9B9B)}]; [self.songContenView addSubview:self.songTextField]; [self.songTextField mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(12); make.right.mas_equalTo(-12); make.top.bottom.equalTo(self.songContenView); }]; self.giftContenView = [[UIView alloc] init]; [self.giftContenView addRoundedCornersWithRadius:11]; self.giftContenView.backgroundColor = RGB16(0xEFF2F8); [self.bgView addSubview:self.giftContenView]; [self.giftContenView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.right.mas_equalTo(-10); make.height.mas_equalTo(41); make.top.equalTo(self.songContenView.mas_bottom).offset(24); }]; self.giftArrow = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"arrowRight"] imageByTintColor:RGB16(0x9B9B9B)]]; [self.giftContenView addSubview:self.giftArrow]; [self.giftArrow mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-12); make.width.height.mas_equalTo(24); make.centerY.equalTo(self.giftContenView); }]; self.giftLabel = [[UILabel alloc] init]; self.giftLabel.text = @"请选择礼物"; self.giftLabel.font = [UIFont systemFontOfSize:16]; self.giftLabel.textColor = RGB16(0x9B9B9B); [self.giftContenView addSubview:self.giftLabel]; [self.giftLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(12); make.right.equalTo(self.giftArrow.mas_left).offset(-12); make.top.bottom.equalTo(self.giftContenView); }]; self.giftBtn = [[UIButton alloc] init]; [self.giftBtn addTarget:self action:@selector(giftAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.giftContenView addSubview:self.giftBtn]; [self.giftBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.giftContenView); }]; self.cancelBtn = [[UIButton alloc] init]; [self.bgView addSubview:self.cancelBtn]; [self.cancelBtn setTitle:@"取消" forState:(UIControlStateNormal)]; [self.cancelBtn addTarget:self action:@selector(hide) forControlEvents:(UIControlEventTouchUpInside)]; [self.cancelBtn setTitleColor:RGB16(0x999999) forState:(UIControlStateNormal)]; self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14]; self.cancelBtn.backgroundColor = RGB16(0xF3F3F3); [self.cancelBtn addRoundedCornersWithRadius:21]; [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(19); make.width.mas_equalTo(110); make.height.mas_equalTo(42); make.bottom.mas_equalTo(-20); }]; self.commitBtn = [[UIButton alloc] init]; [self.bgView addSubview:self.commitBtn]; [self.commitBtn setTitle:@"确认" forState:(UIControlStateNormal)]; [self.commitBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)]; [self.commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)]; self.commitBtn.titleLabel.font = [UIFont systemFontOfSize:14]; self.commitBtn.backgroundColor = QXConfig.themeColor; [self.commitBtn addRoundedCornersWithRadius:21]; [self.commitBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-19); make.width.mas_equalTo(110); make.height.mas_equalTo(42); make.bottom.mas_equalTo(-20); }]; } -(void)giftAction{ if (self.delegate && [self.delegate respondsToSelector:@selector(qx_mineAddSongViewDidSeleteGift)]) { [self.delegate qx_mineAddSongViewDidSeleteGift]; } } -(void)commitAction{ if (![self.songTextField.text isExist]) { showToast(@"请输入歌曲名称"); return; } if (self.songModel == nil) { if (self.giftModel == nil) { showToast(@"请选择礼物"); return; } } if (self.songModel) { self.songModel.song_name = self.songTextField.text; if (self.delegate && [self.delegate respondsToSelector:@selector(qx_mineEditSongViewCommitWithSongModel:)]) { [self.delegate qx_mineEditSongViewCommitWithSongModel:self.songModel]; } return; } if (self.delegate && [self.delegate respondsToSelector:@selector(qx_mineAddSongViewCommitWithSongName:giftModel:)]) { [self.delegate qx_mineAddSongViewCommitWithSongName:self.songTextField.text giftModel:self.giftModel]; } } -(void)textFieldDidBeginEditing:(UITextField *)textField{ [UIView animateWithDuration:0.3 animations:^{ self.bgView.top = 100; }]; } -(void)textFieldDidEndEditing:(UITextField *)textField{ [UIView animateWithDuration:0.3 animations:^{ self.bgView.y = (SCREEN_HEIGHT-300)/2.0; }]; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self endEditing:YES]; } -(void)showInView:(UIView *)view{ self.bgView.y = -SCREEN_HEIGHT; [view addSubview:self]; [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ self.bgView.y = (SCREEN_HEIGHT-300)/2.0; } completion:^(BOOL finished) { }]; } -(void)hide{ [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ self.bgView.y = SCREEN_HEIGHT; } completion:^(BOOL finished) { [self removeFromSuperview]; if (self.delegate && [self.delegate respondsToSelector:@selector(qx_mineAddSongViewDidRemove)]) { [self.delegate qx_mineAddSongViewDidRemove]; } }]; } @end