Files
peko-ios/YuMi/Modules/YMRoom/View/AnimationView/XPRoomTarrowBannerView.m
2023-09-20 18:38:51 +08:00

165 lines
6.0 KiB
Objective-C

//
// XPRoomTarrowBannerView.m
// YuMi
//
// Created by duoban on 2023/9/13.
//
#import "SVGAParser.h"
#import "SVGA.h"
#import "XPRoomTarrowBannerView.h"
#import "XPSVGAPlayer.h"
@interface XPRoomTarrowBannerView()<SVGAPlayerDelegate>
///动画管理类
@property (strong, nonatomic) SVGAParser *parser;
@property (nonatomic, strong) XPSVGAPlayer *giftImageView;
@property(nonatomic,strong) MarqueeLabel *titleView;
@property(nonatomic,strong) UIImageView *bgImageView;
@property(nonatomic,assign) BOOL isH5;
@end
@implementation XPRoomTarrowBannerView
-(instancetype)initWithFrame:(CGRect)frame isH5:(BOOL)isH5{
self = [super initWithFrame:frame];
if(self){
self.isH5 = isH5;
if(isH5 == YES){
[self installUIWithH5];
[self installConstraintsWithH5];
}else{
[self installUI];
[self installConstraints];
}
}
return self;
}
-(void)installUIWithH5{
[self addSubview:self.bgImageView];
[self addSubview:self.giftImageView];
[self addSubview:self.titleView];
self.bgImageView.image = kImage(@"room_tarrow_banner_h5_bg");
self.titleView.fadeLength = 50.0f;
}
-(void)installConstraintsWithH5{
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(28));
make.trailing.mas_equalTo(-kGetScaleWidth(28.5));
make.height.mas_equalTo(kGetScaleWidth(12));
make.centerY.equalTo(self);
}];
}
-(void)installUI{
[self addSubview:self.bgImageView];
[self addSubview:self.giftImageView];
[self addSubview:self.titleView];
}
-(void)installConstraints{
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(54.5));
make.trailing.mas_equalTo(-kGetScaleWidth(29.5));
make.height.mas_equalTo(kGetScaleWidth(12));
make.centerY.equalTo(self);
}];
}
- (void)setGiftH5Info:(PIBaseAnimationViewModel *)giftH5Info{
_giftH5Info = giftH5Info;
NSString *title = _giftH5Info.content;
NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc]initWithString:title attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12 weight:UIFontWeightRegular],NSForegroundColorAttributeName:[UIColor whiteColor]}];
_titleView.attributedText = titleAtt;
if(_isBig == YES){
self.bgImageView.hidden = YES;
[self.parser parseWithNamed:@"pi_room_tarrow_h5_banner" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
self.giftImageView.hidden = NO;
self.giftImageView.videoItem = videoItem;
self.giftImageView.loops = 3;
self.giftImageView.clearsAfterStop = NO;
[self.giftImageView startAnimation];
} failureBlock:^(NSError * _Nonnull error) {
}];
return;
}
self.giftImageView.hidden = YES;
self.bgImageView.hidden = NO;
}
-(void)setGiftInfo:(PIBaseAnimationViewModel *)giftInfo{
_giftInfo = giftInfo;
if(_giftInfo.nick.length > 5){
_giftInfo.nick = [NSString stringWithFormat:@"%@...",[_giftInfo.nick substringToIndex:5]];
}
NSString *title = [NSString stringWithFormat:YMLocalizedString(@"XPRoomTarrowBannerView0"),_giftInfo.nick,_giftInfo.drawGoldNum];
NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc]initWithString:title attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12 weight:UIFontWeightRegular],NSForegroundColorAttributeName:[UIColor whiteColor]}];
[titleAtt addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12 weight:UIFontWeightRegular],NSForegroundColorAttributeName:UIColorFromRGB(0xFFEE8F)} range:[title rangeOfString:_giftInfo.nick]];
[titleAtt addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12 weight:UIFontWeightRegular],NSForegroundColorAttributeName:UIColorFromRGB(0xFFEE8F)} range:[title rangeOfString:_giftInfo.drawGoldNum]];
_titleView.attributedText = titleAtt;
if(_isBig == YES){
self.bgImageView.hidden = YES;
[self.parser parseWithNamed:@"pi_room_tarrow_banner" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
self.giftImageView.hidden = NO;
self.giftImageView.videoItem = videoItem;
self.giftImageView.loops = 1;
self.giftImageView.clearsAfterStop = NO;
[self.giftImageView startAnimation];
} failureBlock:^(NSError * _Nonnull error) {
}];
return;
}
self.giftImageView.hidden = YES;
self.bgImageView.hidden = NO;
}
#pragma mark - 懒加载
- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player{
NSLog(@"11111");
}
- (XPSVGAPlayer *)giftImageView {
if (!_giftImageView) {
_giftImageView = [[XPSVGAPlayer alloc]init];
_giftImageView.backgroundColor = [UIColor clearColor];
_giftImageView.userInteractionEnabled = NO;
_giftImageView.delegate = self;
}
return _giftImageView;
}
- (SVGAParser *)parser {
if (!_parser) {
_parser = [[SVGAParser alloc]init];
}
return _parser;
}
- (MarqueeLabel *)titleView{
if(!_titleView){
_titleView = [[MarqueeLabel alloc] init];
_titleView.scrollDuration = 6.0;
_titleView.fadeLength = 8.0f;
_titleView.textAlignment = NSTextAlignmentCenter;
}
return _titleView;
}
- (UIImageView *)bgImageView{
if(!_bgImageView){
_bgImageView = [UIImageView new];
_bgImageView.image = kImage(@"room_tarrow_banner_bg");
}
return _bgImageView;
}
@end