2023-07-14 18:50:55 +08:00
|
|
|
|
//
|
|
|
|
|
// YMRoomBaseUIView.m
|
|
|
|
|
// YUMI
|
|
|
|
|
//
|
|
|
|
|
// Created by YUMI on 2021/10/11.
|
|
|
|
|
// 最下面的View
|
|
|
|
|
|
|
|
|
|
#import "XPRoomBackContainerView.h"
|
|
|
|
|
///Third
|
|
|
|
|
#import <Masonry/Masonry.h>
|
|
|
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
|
|
|
|
///Model
|
|
|
|
|
#import "RoomInfoModel.h"
|
|
|
|
|
//SVGA动画播放
|
|
|
|
|
#import "SVGA.h"
|
|
|
|
|
#import "SVGAParserManager.h"
|
|
|
|
|
///Tool
|
|
|
|
|
#import "YUMIMacroUitls.h"
|
|
|
|
|
#import "XNDJTDDLoadingTool.h"
|
|
|
|
|
#import "NetImageView.h"
|
|
|
|
|
|
|
|
|
|
@interface XPRoomBackContainerView ()
|
|
|
|
|
///背景图片
|
|
|
|
|
@property (nonatomic,strong) NetImageView *backImageView;
|
|
|
|
|
///动态背景
|
|
|
|
|
@property (nonatomic, strong) SVGAImageView *svgDisplayView;
|
|
|
|
|
@property (nonatomic, strong) SVGAParserManager *parserManager;
|
|
|
|
|
///host 代理
|
|
|
|
|
@property (nonatomic,weak) id<RoomHostDelegate>delegate;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation XPRoomBackContainerView
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithdelegate:(id<RoomHostDelegate>)delegate {
|
|
|
|
|
self = [super init];
|
|
|
|
|
if (self) {
|
|
|
|
|
self.delegate = delegate;
|
|
|
|
|
[self initSubViews];
|
|
|
|
|
[self initSubViewConstraints];
|
|
|
|
|
self.clipsToBounds = YES;
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Private Method
|
|
|
|
|
- (void)initSubViews {
|
|
|
|
|
[self addSubview:self.backImageView];
|
|
|
|
|
[self addSubview:self.svgDisplayView];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)initSubViewConstraints {
|
|
|
|
|
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.edges.mas_equalTo(self);
|
|
|
|
|
}];
|
|
|
|
|
[self.svgDisplayView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.edges.mas_equalTo(self);
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)onRoomEntered {
|
|
|
|
|
[self updateRoomBg];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)onRoomUpdate {
|
|
|
|
|
[self updateRoomBg];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)updateRoomBg {
|
|
|
|
|
RoomInfoModel *roomInfo = [self.delegate getRoomInfo];
|
|
|
|
|
if (roomInfo.backPic.length > 0) {
|
|
|
|
|
///MARK:更改图片拉伸策略 BY lvjunhang, 2018-12-03,原值为:UIViewContentModeScaleAspectFit
|
|
|
|
|
self.backImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
|
if ([roomInfo.backPic containsString:@".svga"]) { //房间背景是SVGA动态背景
|
2023-07-21 14:07:04 +08:00
|
|
|
|
|
2023-07-14 18:50:55 +08:00
|
|
|
|
@weakify(self);
|
|
|
|
|
[self.parserManager loadSvgaWithURL:[NSURL URLWithString:roomInfo.backPic] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
|
|
|
|
|
@strongify(self);
|
|
|
|
|
if (videoItem != nil) {
|
2023-07-21 14:07:04 +08:00
|
|
|
|
self.svgDisplayView.hidden = NO;
|
2023-07-14 18:50:55 +08:00
|
|
|
|
CGFloat width = videoItem.videoSize.width;
|
|
|
|
|
CGFloat height = videoItem.videoSize.height;
|
|
|
|
|
if (width > height) {
|
|
|
|
|
self.svgDisplayView.contentMode = UIViewContentModeScaleAspectFit;
|
|
|
|
|
} else {//高大于宽
|
|
|
|
|
CGFloat resizeH = KScreenWidth * height / width;//按照屏幕的宽度去缩放,获得高度
|
|
|
|
|
if (resizeH > KScreenHeight) {//如果大于屏幕高度,填充
|
|
|
|
|
self.svgDisplayView.contentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
|
} else {//小于屏幕高度,
|
|
|
|
|
self.svgDisplayView.contentMode = UIViewContentModeScaleAspectFit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self.svgDisplayView.loops = INT_MAX;
|
|
|
|
|
self.svgDisplayView.clearsAfterStop = NO;
|
|
|
|
|
self.svgDisplayView.videoItem = videoItem;
|
|
|
|
|
[self.svgDisplayView startAnimation];
|
|
|
|
|
}
|
|
|
|
|
} failureBlock:^(NSError * _Nullable error) {
|
|
|
|
|
[XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"XPRoomBackContainerView0")];
|
|
|
|
|
}];
|
|
|
|
|
} else { //房间背景是静态背景
|
|
|
|
|
[self.svgDisplayView stopAnimation];
|
|
|
|
|
self.svgDisplayView.hidden = YES;
|
|
|
|
|
self.backImageView.imageUrl = roomInfo.backPic;
|
|
|
|
|
}
|
|
|
|
|
}else { //没有设置背景,显示默认背景加高斯模糊
|
|
|
|
|
if (roomInfo.type == RoomType_Anchor) {
|
|
|
|
|
self.svgDisplayView.hidden = NO;
|
|
|
|
|
@weakify(self);
|
|
|
|
|
NSString * bgString = [NSString stringWithFormat:@"%@/anchor_room_bg.svga", API_Image_URL];
|
2023-12-06 17:40:56 +08:00
|
|
|
|
NSURL *bgUrl = [NSURL URLWithString:bgString];
|
2023-07-14 18:50:55 +08:00
|
|
|
|
[self.parserManager loadSvgaWithURL:bgUrl completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
|
|
|
|
|
@strongify(self);
|
|
|
|
|
if (videoItem != nil) {
|
|
|
|
|
CGFloat width = videoItem.videoSize.width;
|
|
|
|
|
CGFloat height = videoItem.videoSize.height;
|
|
|
|
|
if (width > height) {
|
|
|
|
|
self.svgDisplayView.contentMode = UIViewContentModeScaleAspectFit;
|
|
|
|
|
} else {//高大于宽
|
|
|
|
|
CGFloat resizeH = KScreenWidth * height / width;//按照屏幕的宽度去缩放,获得高度
|
|
|
|
|
if (resizeH > KScreenHeight) {//如果大于屏幕高度,填充
|
|
|
|
|
self.svgDisplayView.contentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
|
} else {//小于屏幕高度,
|
|
|
|
|
self.svgDisplayView.contentMode = UIViewContentModeScaleAspectFit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self.svgDisplayView.loops = INT_MAX;
|
|
|
|
|
self.svgDisplayView.clearsAfterStop = NO;
|
|
|
|
|
self.svgDisplayView.videoItem = videoItem;
|
|
|
|
|
[self.svgDisplayView startAnimation];
|
|
|
|
|
}
|
|
|
|
|
} failureBlock:^(NSError * _Nullable error) {
|
|
|
|
|
[XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"XPRoomBackContainerView1")];
|
|
|
|
|
}];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
self.backImageView.image = [UIImage imageNamed:@"room_background"];
|
|
|
|
|
[self.svgDisplayView stopAnimation];
|
|
|
|
|
self.svgDisplayView.hidden = YES;
|
|
|
|
|
self.backImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Getters And Setters
|
|
|
|
|
- (NetImageView *)backImageView {
|
|
|
|
|
if (!_backImageView) {
|
2023-07-21 14:07:04 +08:00
|
|
|
|
NetImageConfig *config = [[NetImageConfig alloc]init];
|
|
|
|
|
config.placeHolder = [UIImage imageNamed:@"room_background"];
|
|
|
|
|
_backImageView = [[NetImageView alloc] initWithConfig:config];
|
2023-07-14 18:50:55 +08:00
|
|
|
|
_backImageView.userInteractionEnabled = YES;
|
2023-07-21 14:07:04 +08:00
|
|
|
|
|
|
|
|
|
\
|
2023-07-14 18:50:55 +08:00
|
|
|
|
_backImageView.layer.masksToBounds = YES;
|
|
|
|
|
_backImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
|
}
|
|
|
|
|
return _backImageView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (SVGAImageView *)svgDisplayView {
|
|
|
|
|
if (_svgDisplayView == nil) {
|
|
|
|
|
_svgDisplayView = [[SVGAImageView alloc]init];
|
|
|
|
|
_svgDisplayView.contentMode = UIViewContentModeScaleToFill;
|
|
|
|
|
_svgDisplayView.userInteractionEnabled = NO;
|
|
|
|
|
_svgDisplayView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
|
|
|
|
|
_svgDisplayView.hidden = YES;
|
|
|
|
|
_svgDisplayView.backgroundColor = [UIColor clearColor];
|
|
|
|
|
}
|
|
|
|
|
return _svgDisplayView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (SVGAParserManager *)parserManager {
|
|
|
|
|
if (!_parserManager) {
|
|
|
|
|
_parserManager = [[SVGAParserManager alloc]init];
|
|
|
|
|
}
|
|
|
|
|
return _parserManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|