2021-10-14 21:10:04 +08:00
|
|
|
|
//
|
|
|
|
|
// XPRoomBaseUIView.m
|
|
|
|
|
// xplan-ios
|
|
|
|
|
//
|
|
|
|
|
// Created by 冯硕 on 2021/10/11.
|
|
|
|
|
// 最下面的View
|
|
|
|
|
|
2021-10-18 19:10:13 +08:00
|
|
|
|
#import "XPRoomBackContainerView.h"
|
2021-10-14 21:10:04 +08:00
|
|
|
|
///Third
|
|
|
|
|
#import <Masonry/Masonry.h>
|
2022-02-16 19:38:15 +08:00
|
|
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
2021-11-18 15:34:52 +08:00
|
|
|
|
///Model
|
|
|
|
|
#import "RoomInfoModel.h"
|
2022-02-16 19:38:15 +08:00
|
|
|
|
//SVGA动画播放
|
|
|
|
|
#import "SVGA.h"
|
|
|
|
|
#import "SVGAParserManager.h"
|
|
|
|
|
///Tool
|
|
|
|
|
#import "XPMacro.h"
|
|
|
|
|
#import "XCHUDTool.h"
|
|
|
|
|
#import "NetImageView.h"
|
2021-12-06 20:28:06 +08:00
|
|
|
|
|
|
|
|
|
@interface XPRoomBackContainerView ()
|
|
|
|
|
///背景图片
|
2022-02-16 19:38:15 +08:00
|
|
|
|
@property (nonatomic,strong) NetImageView *backImageView;
|
|
|
|
|
@property (nonatomic, strong) SVGAImageView *svgDisplayView;
|
|
|
|
|
@property (nonatomic, strong) SVGAParserManager *parserManager;
|
2021-12-06 20:28:06 +08:00
|
|
|
|
///host 代理
|
2021-11-18 15:34:52 +08:00
|
|
|
|
@property (nonatomic,weak) id<RoomHostDelegate>delegate;
|
|
|
|
|
|
2021-10-14 21:10:04 +08:00
|
|
|
|
@end
|
|
|
|
|
|
2021-10-18 19:10:13 +08:00
|
|
|
|
@implementation XPRoomBackContainerView
|
2021-10-14 21:10:04 +08:00
|
|
|
|
|
2021-11-18 15:34:52 +08:00
|
|
|
|
- (instancetype)initWithdelegate:(id<RoomHostDelegate>)delegate {
|
|
|
|
|
self = [super init];
|
2021-10-14 21:10:04 +08:00
|
|
|
|
if (self) {
|
2021-11-18 15:34:52 +08:00
|
|
|
|
self.delegate = delegate;
|
2021-10-14 21:10:04 +08:00
|
|
|
|
[self initSubViews];
|
|
|
|
|
[self initSubViewConstraints];
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-18 21:29:19 +08:00
|
|
|
|
#pragma mark - Private Method
|
|
|
|
|
- (void)initSubViews {
|
2022-02-16 19:38:15 +08:00
|
|
|
|
[self addSubview:self.svgDisplayView];
|
2021-11-18 21:29:19 +08:00
|
|
|
|
[self addSubview:self.backImageView];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)initSubViewConstraints {
|
2022-02-16 19:38:15 +08:00
|
|
|
|
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.edges.mas_equalTo(self);
|
|
|
|
|
}];
|
|
|
|
|
[self.svgDisplayView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.edges.mas_equalTo(self);
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)onRoomUpdate {
|
|
|
|
|
[self updateRoomBg];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)updateRoomBg {
|
|
|
|
|
RoomInfoModel *roomInfo = [self.delegate getRoomInfo];
|
|
|
|
|
// UserInfoModel *userInfo = [self.delegate getUserInfo];
|
|
|
|
|
if (roomInfo.backPic.length > 0) {
|
|
|
|
|
///MARK:更改图片拉伸策略 BY lvjunhang, 2018-12-03,原值为:UIViewContentModeScaleAspectFit
|
|
|
|
|
self.backImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
|
if ([roomInfo.backPic containsString:@".svga"]) { //房间背景是SVGA动态背景
|
|
|
|
|
self.backImageView.hidden = YES;
|
|
|
|
|
self.svgDisplayView.hidden = NO;
|
|
|
|
|
@weakify(self);
|
|
|
|
|
//@"https://img.erbanyy.com/Noble_OpenEffect_5.svga"
|
|
|
|
|
[self.parserManager loadSvgaWithURL:[NSURL URLWithString:roomInfo.backPic] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
|
|
|
|
|
@strongify(self);
|
|
|
|
|
self.svgDisplayView.loops = INT_MAX;
|
|
|
|
|
self.svgDisplayView.clearsAfterStop = NO;
|
|
|
|
|
self.svgDisplayView.videoItem = videoItem;
|
|
|
|
|
[self.svgDisplayView startAnimation];
|
|
|
|
|
} failureBlock:^(NSError * _Nullable error) {
|
|
|
|
|
[XCHUDTool showErrorWithMessage:@"贵族专属背景图加载失败"];
|
|
|
|
|
}];
|
|
|
|
|
} else { //房间背景是静态背景
|
|
|
|
|
[self.svgDisplayView stopAnimation];
|
|
|
|
|
self.svgDisplayView.hidden = YES;
|
|
|
|
|
self.backImageView.hidden = NO;
|
|
|
|
|
self.backImageView.imageUrl = roomInfo.backPic;
|
|
|
|
|
}
|
|
|
|
|
}else { //没有设置背景,显示默认背景加高斯模糊
|
|
|
|
|
if (roomInfo.type == RoomType_Anchor) {
|
|
|
|
|
self.backImageView.hidden = YES;
|
|
|
|
|
self.svgDisplayView.hidden = NO;
|
|
|
|
|
@weakify(self);
|
|
|
|
|
NSString *bgString = [[NSBundle mainBundle] pathForResource:@"anchor_room_bg" ofType:@"svga"];
|
|
|
|
|
NSURL *bgUrl = [NSURL fileURLWithPath:bgString];
|
|
|
|
|
[self.parserManager loadSvgaWithURL:bgUrl completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
|
|
|
|
|
@strongify(self);
|
|
|
|
|
self.svgDisplayView.loops = INT_MAX;
|
|
|
|
|
self.svgDisplayView.clearsAfterStop = NO;
|
|
|
|
|
self.svgDisplayView.videoItem = videoItem;
|
|
|
|
|
[self.svgDisplayView startAnimation];
|
|
|
|
|
} failureBlock:^(NSError * _Nullable error) {
|
|
|
|
|
[XCHUDTool showErrorWithMessage:@"个播背景图加载失败"];
|
|
|
|
|
}];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
self.svgDisplayView.hidden = YES;
|
|
|
|
|
self.backImageView.hidden = NO;
|
|
|
|
|
self.backImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
|
}
|
2021-11-18 21:29:19 +08:00
|
|
|
|
}
|
2022-02-16 19:38:15 +08:00
|
|
|
|
|
2021-10-14 21:10:04 +08:00
|
|
|
|
#pragma mark - Getters And Setters
|
2022-02-16 19:38:15 +08:00
|
|
|
|
- (NetImageView *)backImageView {
|
2021-10-14 21:10:04 +08:00
|
|
|
|
if (!_backImageView) {
|
2022-02-16 19:38:15 +08:00
|
|
|
|
_backImageView = [[NetImageView alloc] init];
|
2021-10-14 21:10:04 +08:00
|
|
|
|
_backImageView.userInteractionEnabled = YES;
|
|
|
|
|
_backImageView.image = [UIImage imageNamed:@"room_background"];
|
|
|
|
|
_backImageView.layer.masksToBounds = YES;
|
|
|
|
|
_backImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
|
}
|
|
|
|
|
return _backImageView;
|
|
|
|
|
}
|
2022-02-16 19:38:15 +08:00
|
|
|
|
|
|
|
|
|
- (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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-14 21:10:04 +08:00
|
|
|
|
@end
|