193 lines
6.5 KiB
Objective-C
193 lines
6.5 KiB
Objective-C
//
|
|
// XPNewHomePartyAudioView.m
|
|
// YuMi
|
|
//
|
|
// Created by duoban on 2023/9/4.
|
|
//
|
|
|
|
#import "XPNewHomePartyAudioView.h"
|
|
#import "XPSkillCardPlayerManager.h"
|
|
#import <AFNetworking.h>
|
|
#import <SVGA.h>
|
|
@interface XPNewHomePartyAudioView ()
|
|
///背景
|
|
@property(nonatomic,strong) UIView *bgView;
|
|
///签名
|
|
@property(nonatomic,strong) UILabel *signatureView;
|
|
///播放按钮
|
|
@property(nonatomic,strong) UIButton *playBnt;
|
|
///图标
|
|
@property(nonatomic,strong) UIImageView *audioBgView;
|
|
///时间
|
|
@property(nonatomic,strong) UILabel *timeView;
|
|
///播放动效
|
|
@property(nonatomic,strong) SVGAParser *parser;
|
|
@property(nonatomic,strong) SVGAImageView *playImageView;
|
|
@end
|
|
@implementation XPNewHomePartyAudioView
|
|
|
|
-(instancetype)initWithFrame:(CGRect)frame{
|
|
self = [super initWithFrame:frame];
|
|
if(self){
|
|
[self installUI];
|
|
[self installConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
-(void)installUI{
|
|
UIView *subView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, kGetScaleWidth(13))];
|
|
[self addSubview:subView];
|
|
subView.tag = 100001;
|
|
subView.backgroundColor = UIColorFromRGB(0xF5F6FA);
|
|
[subView setCornerWithLeftTopCorner:kGetScaleWidth(2) rightTopCorner:0 bottomLeftCorner:0 bottomRightCorner:0 size:CGSizeMake(20, kGetScaleWidth(13))];
|
|
[self addSubview:self.bgView];
|
|
[self.bgView addSubview:self.signatureView];
|
|
[self.bgView addSubview:self.playBnt];
|
|
[self.bgView addSubview:self.audioBgView];
|
|
[self.bgView addSubview:self.playImageView];
|
|
[self.bgView addSubview:self.timeView];
|
|
@kWeakify(self);
|
|
[self.parser parseWithNamed:@"pi_home_new_play" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
@kStrongify(self);
|
|
self.playImageView.loops = INT_MAX;
|
|
self.playImageView.clearsAfterStop = NO;
|
|
self.playImageView.videoItem = videoItem;
|
|
[self.playImageView startAnimation];
|
|
} failureBlock:^(NSError * _Nullable error) {
|
|
}];
|
|
}
|
|
-(void)installConstraints{
|
|
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.top.bottom.equalTo(self);
|
|
make.width.mas_lessThanOrEqualTo(kGetScaleWidth(192));
|
|
}];
|
|
[self.playBnt mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.height.mas_equalTo(kGetScaleWidth(26));
|
|
make.top.mas_equalTo(kGetScaleWidth(0));
|
|
make.leading.mas_equalTo(kGetScaleWidth(6));
|
|
}];
|
|
[self.audioBgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(kGetScaleWidth(31));
|
|
make.centerY.equalTo(self.bgView);
|
|
make.width.mas_equalTo(kGetScaleWidth(22));
|
|
make.height.mas_equalTo(kGetScaleWidth(10));
|
|
}];
|
|
[self.playImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self.audioBgView);
|
|
}];
|
|
[self.timeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(kGetScaleWidth(54));
|
|
make.height.mas_equalTo(kGetScaleWidth(15));make.centerY.equalTo(self.bgView);
|
|
}];
|
|
[self.signatureView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.equalTo(self.bgView).inset(kGetScaleWidth(10));
|
|
make.centerY.equalTo(self.bgView);
|
|
}];
|
|
}
|
|
-(void)playAudioAction:(UIButton *)sender{
|
|
_playBnt.selected = !_playBnt.selected;
|
|
_audioBgView.hidden = _playBnt.selected;
|
|
_playImageView.hidden = !_playBnt.selected;
|
|
if(self.delegate && [self.delegate respondsToSelector:@selector(xPNewHomePartyAudioView:didClickPlaySound:)]){
|
|
[self.delegate xPNewHomePartyAudioView:self didClickPlaySound:_playBnt.selected];
|
|
}
|
|
}
|
|
-(void)setUserVoice:(NSString *)userVoice{
|
|
_userVoice = userVoice;
|
|
_playBnt.hidden = NO;
|
|
_audioBgView.hidden = NO;
|
|
_playImageView.hidden = NO;
|
|
_timeView.hidden = NO;
|
|
_signatureView.hidden = YES;
|
|
_signatureView.text = @"";
|
|
|
|
[self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.top.bottom.equalTo(self);
|
|
make.width.mas_equalTo(kGetScaleWidth(85));
|
|
}];
|
|
}
|
|
-(void)setUserDesc:(NSString *)userDesc{
|
|
_userDesc = userDesc;
|
|
_playBnt.hidden = YES;
|
|
_audioBgView.hidden = YES;
|
|
_playImageView.hidden = YES;
|
|
_timeView.hidden = YES;
|
|
_signatureView.hidden = NO;
|
|
_signatureView.text = _userDesc;
|
|
[self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.top.bottom.equalTo(self);
|
|
make.width.mas_lessThanOrEqualTo(kGetScaleWidth(192));
|
|
}];
|
|
}
|
|
-(void)setVoiceDura:(NSString *)voiceDura{
|
|
_voiceDura = voiceDura;
|
|
_timeView.text = [NSString stringWithFormat:@"%@\"",_voiceDura];
|
|
}
|
|
- (void)setIsHiddenVew:(BOOL)isHiddenVew{
|
|
_isHiddenVew = isHiddenVew;
|
|
UIView *view = [self viewWithTag:100001];
|
|
view.hidden = _isHiddenVew;
|
|
_bgView.hidden = _isHiddenVew;
|
|
}
|
|
- (void)setIsPlay:(BOOL)isPlay{
|
|
_isPlay = isPlay;
|
|
_playBnt.selected = _isPlay;
|
|
_playImageView.hidden = !_isPlay;
|
|
_audioBgView.hidden = _isPlay;
|
|
}
|
|
#pragma mark - 懒加载
|
|
- (UIView *)bgView{
|
|
if(!_bgView){
|
|
_bgView = [UIView new];
|
|
_bgView.backgroundColor = UIColorFromRGB(0xF5F6FA);
|
|
_bgView.layer.cornerRadius = kGetScaleWidth(26)/2;
|
|
_bgView.layer.masksToBounds = YES;
|
|
|
|
}
|
|
return _bgView;
|
|
}
|
|
- (UILabel *)signatureView{
|
|
if(!_signatureView){
|
|
_signatureView = [UILabel labelInitWithText:@"" font:kFontRegular(10) textColor:UIColorFromRGB(0x8A8CAB)];
|
|
}
|
|
return _signatureView;
|
|
}
|
|
- (UIButton *)playBnt{
|
|
if(!_playBnt){
|
|
_playBnt = [UIButton new];
|
|
[_playBnt setImage:kImage(@"home_audio_play_play") forState:UIControlStateNormal];
|
|
[_playBnt setImage:kImage(@"home_audio_stop") forState:UIControlStateSelected];
|
|
[_playBnt addTarget:self action:@selector(playAudioAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _playBnt;
|
|
}
|
|
- (UIImageView *)audioBgView{
|
|
if(!_audioBgView){
|
|
_audioBgView = [UIImageView new];
|
|
_audioBgView.image = kImage(@"home_audio_icon");
|
|
}
|
|
return _audioBgView;
|
|
}
|
|
- (UILabel *)timeView{
|
|
if(!_timeView){
|
|
_timeView = [UILabel labelInitWithText:@"0\"" font:kFontMedium(12) textColor:UIColorFromRGB(0x1F1B4F)];
|
|
}
|
|
return _timeView;
|
|
}
|
|
- (SVGAParser *)parser{
|
|
if(!_parser){
|
|
_parser = [SVGAParser new];
|
|
}
|
|
return _parser;
|
|
}
|
|
- (SVGAImageView *)playImageView {
|
|
if (_playImageView == nil) {
|
|
_playImageView = [[SVGAImageView alloc]init];
|
|
_playImageView.contentMode = UIViewContentModeScaleToFill;
|
|
_playImageView.backgroundColor = [UIColor clearColor];
|
|
_playImageView.hidden = NO;
|
|
}
|
|
return _playImageView;
|
|
}
|
|
@end
|