145 lines
5.8 KiB
Mathematica
145 lines
5.8 KiB
Mathematica
|
|
//
|
||
|
|
// QXRoomBgMusicView.m
|
||
|
|
// QXLive
|
||
|
|
//
|
||
|
|
// Created by 启星 on 2025/6/23.
|
||
|
|
//
|
||
|
|
|
||
|
|
#import "QXRoomBgMusicView.h"
|
||
|
|
#import "MarqueeLabel.h"
|
||
|
|
|
||
|
|
@interface QXRoomBgMusicView()
|
||
|
|
@property (nonatomic,strong)UIImageView *bgImageView;
|
||
|
|
@property (nonatomic,strong)UIImageView *musicCover;
|
||
|
|
@property (nonatomic,strong)MarqueeLabel *nameLabel;
|
||
|
|
@property (nonatomic,strong)UILabel *singerLabel;
|
||
|
|
@property (nonatomic,strong)UILabel *timeLabel;
|
||
|
|
@property (nonatomic,strong)UIButton *closeBtn;
|
||
|
|
|
||
|
|
@property (nonatomic,strong)UIButton *moreBtn;
|
||
|
|
@property (nonatomic,strong)UIButton *nextBtn;
|
||
|
|
@property (nonatomic,strong)UIButton *playBtn;
|
||
|
|
@end
|
||
|
|
@implementation QXRoomBgMusicView
|
||
|
|
|
||
|
|
- (instancetype)init
|
||
|
|
{
|
||
|
|
self = [super init];
|
||
|
|
if (self) {
|
||
|
|
self.frame = CGRectMake(SCREEN_WIDTH-215-12, kSafeAreaTop+56, 214, 97);
|
||
|
|
[self initSubviews];
|
||
|
|
}
|
||
|
|
return self;
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)initSubviews{
|
||
|
|
[self addRoundedCornersWithRadius:16];
|
||
|
|
self.backgroundColor = RGB16A(0xffffff, 0.7);
|
||
|
|
self.bgImageView = [[UIImageView alloc] initWithFrame:self.bounds];
|
||
|
|
[self addSubview:self.bgImageView];
|
||
|
|
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
|
||
|
|
[self addGestureRecognizer:panRecognizer];
|
||
|
|
self.musicCover = [[UIImageView alloc] initWithFrame:CGRectMake(12, 12, 44, 44)];
|
||
|
|
[self.musicCover addRoundedCornersWithRadius:2];
|
||
|
|
self.musicCover.contentMode = UIViewContentModeScaleAspectFill;
|
||
|
|
[self addSubview:self.musicCover];
|
||
|
|
|
||
|
|
self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, self.height-40-2, 58, 40)];
|
||
|
|
self.timeLabel.font = [UIFont systemFontOfSize:9];
|
||
|
|
self.timeLabel.textColor = RGB16(0x666666);
|
||
|
|
[self addSubview:self.timeLabel];
|
||
|
|
|
||
|
|
self.nameLabel = [[MarqueeLabel alloc] initWithFrame:CGRectMake(self.musicCover.right+4, self.musicCover.top, 95, 18)];
|
||
|
|
self.nameLabel.textColor = QXConfig.textColor;
|
||
|
|
self.nameLabel.font = [UIFont systemFontOfSize:12];
|
||
|
|
[self addSubview:self.nameLabel];
|
||
|
|
|
||
|
|
self.singerLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.musicCover.right+4, self.nameLabel.bottom+4, 95, 18)];
|
||
|
|
self.singerLabel.textColor = QXConfig.textColor;
|
||
|
|
self.singerLabel.font = [UIFont systemFontOfSize:12];
|
||
|
|
[self addSubview:self.singerLabel];
|
||
|
|
|
||
|
|
self.closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.width-40, 0, 40, 40)];
|
||
|
|
[self.closeBtn setImage:[UIImage imageNamed:@"wallet_close"] forState:(UIControlStateNormal)];
|
||
|
|
[self.closeBtn addTarget:self action:@selector(closeAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||
|
|
[self addSubview:self.closeBtn];
|
||
|
|
|
||
|
|
|
||
|
|
self.moreBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.nameLabel.left, self.height-40-2, 40, 40)];
|
||
|
|
[self.moreBtn setImage:[UIImage imageNamed:@"room_music_more"] forState:(UIControlStateNormal)];
|
||
|
|
[self.moreBtn addTarget:self action:@selector(moreAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||
|
|
[self addSubview:self.moreBtn];
|
||
|
|
|
||
|
|
self.nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.width-25-40, self.moreBtn.top, 40, 40)];
|
||
|
|
[self.nextBtn setImage:[UIImage imageNamed:@"room_music_next"] forState:(UIControlStateNormal)];
|
||
|
|
[self.nextBtn addTarget:self action:@selector(nextAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||
|
|
[self addSubview:self.nextBtn];
|
||
|
|
|
||
|
|
self.playBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.moreBtn.right+(self.nextBtn.left-self.moreBtn.right-40)/2, self.moreBtn.top, 40, 40)];
|
||
|
|
[self.playBtn setImage:[UIImage imageNamed:@"room_music_pause"] forState:(UIControlStateNormal)];
|
||
|
|
[self.playBtn setImage:[UIImage imageNamed:@"room_music_play"] forState:(UIControlStateSelected)];
|
||
|
|
self.playBtn.selected = YES;
|
||
|
|
[self.playBtn addTarget:self action:@selector(playAction) forControlEvents:(UIControlEventTouchUpInside)];
|
||
|
|
[self addSubview:self.playBtn];
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)moreAction{
|
||
|
|
if (self.moreActionBlock) {
|
||
|
|
self.moreActionBlock();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
-(void)playAction{
|
||
|
|
if (self.pauseActionBlock) {
|
||
|
|
self.pauseActionBlock(self.playBtn);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
-(void)nextAction{
|
||
|
|
if (self.nextActionBlock) {
|
||
|
|
self.nextActionBlock();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
-(void)setSongModel:(QXSongListModel *)songModel{
|
||
|
|
_songModel = songModel;
|
||
|
|
self.playBtn.selected = NO;
|
||
|
|
[self.musicCover sd_setImageWithURL:[NSURL URLWithString:songModel.poster]];
|
||
|
|
self.nameLabel.text = songModel.song_name;
|
||
|
|
self.singerLabel.text = songModel.singer;
|
||
|
|
self.timeLabel.text = [NSString stringWithFormat:@"00:00/%02ld:%02ld",songModel.duration/60,songModel.duration%60];
|
||
|
|
}
|
||
|
|
-(void)setProgress:(NSUInteger)progress{
|
||
|
|
_progress = progress;
|
||
|
|
NSInteger minutes = progress/1000/60;
|
||
|
|
NSInteger second = progress/1000%60;
|
||
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||
|
|
self.timeLabel.text = [NSString stringWithFormat:@"%02ld:%02ld/%02ld:%02ld",minutes,second,self.songModel.duration/60,self.songModel.duration%60];
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)handlePan:(UIPanGestureRecognizer*)recognizer{
|
||
|
|
if (recognizer.state == UIGestureRecognizerStateEnded) {
|
||
|
|
NSLog(@"拖动结束");
|
||
|
|
}
|
||
|
|
CGPoint translation = [recognizer translationInView:self.viewController.view];
|
||
|
|
CGPoint panCenter = CGPointMake(recognizer.view.center.x + translation.x,
|
||
|
|
recognizer.view.center.y + translation.y);
|
||
|
|
if (panCenter.x-214/2 <= 0 || panCenter.x+214/2 >= SCREEN_WIDTH || panCenter.y < kSafeAreaTop || panCenter.y> SCREEN_HEIGHT-kSafeAreaBottom) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
|
||
|
|
recognizer.view.center.y + translation.y);
|
||
|
|
[recognizer setTranslation:CGPointZero inView:self.viewController.view];
|
||
|
|
}
|
||
|
|
-(void)closeAction{
|
||
|
|
if (self.closeActionBlock) {
|
||
|
|
self.closeActionBlock();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)showInView:(UIView *)view{
|
||
|
|
[view addSubview:self];
|
||
|
|
}
|
||
|
|
@end
|