// // YMRoomLuckyBigPrizeView.m // YUMI // // Created by YUMI on 2022/6/15. // #import "XPRoomLuckyBigPrizeView.h" ///Third #import #import "SVGAParser.h" #import "SVGA.h" ///Tool #import "DJDKMIMOMColor.h" #import "YUMIMacroUitls.h" ///Model #import "XPGiftBigPrizeModel.h" ///View #import "XPSVGAPlayer.h" @interface XPRoomLuckyBigPrizeView () ///动画管理类 @property (strong, nonatomic) SVGAParser *parser; @property (nonatomic, strong) XPSVGAPlayer *giftImageView; @end @implementation XPRoomLuckyBigPrizeView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; [self initSubViewConstraints]; } return self; } #pragma mark - Private Method - (void)initSubViews { [self addSubview:self.giftImageView]; UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognizer:)]; [self addGestureRecognizer:tap]; } - (void)initSubViewConstraints { [self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(self); }]; } #pragma mark - Event Response - (void)tapRecognizer:(UITapGestureRecognizer *)tap { if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomLuckyBigPrizeView:luckyGiftInfo:)]) { [self.delegate xPRoomLuckyBigPrizeView:self luckyGiftInfo:self.giftInfo]; } } #pragma mark - Getters And Setters - (void)setGiftInfo:(PIBaseAnimationViewModel*)giftInfo { _giftInfo = giftInfo; if (_giftInfo) { NSString * nick = _giftInfo.nick; if (nick.length > 6) { nick = [nick substringToIndex:6]; } CGFloat fontSize = 22; NSDictionary * dic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize], NSForegroundColorAttributeName:[UIColor whiteColor]}; NSDictionary * mainDic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize], NSForegroundColorAttributeName:[DJDKMIMOMColor appMainColor]}; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init]; [attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"恭喜 " attributes:dic]]; if (nick) { [attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:nick attributes:mainDic]]; } [attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:YMLocalizedString(@"XPRoomLuckyBigPrizeView1"),_giftInfo.luckyBagName] attributes:dic]]; if (giftInfo.goldPrice) { [attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:giftInfo.goldPrice attributes:mainDic]]; } [attributedString appendAttributedString:[[NSMutableAttributedString alloc] initWithString:giftInfo.giftName attributes:mainDic]]; NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new]; paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping; paragraphStyle.alignment = NSTextAlignmentLeft; paragraphStyle.lineSpacing = 4.0f;//行间距 // 强制排版(从左到右) paragraphStyle.alignment = NSTextAlignmentLeft; paragraphStyle.baseWritingDirection = NSWritingDirectionLeftToRight; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributedString.length)]; if (_giftInfo.isInRoomVisiable) { [self.giftImageView setHidden:YES forKey:@"img_206"]; } else { [self.giftImageView setHidden:NO forKey:@"img_206"]; } @kWeakify(self); [self.giftImageView setAttributedText:attributedString forKey:@"fdpp_copywriting"]; NSString * anatomiser1Name = [NSString stringWithFormat:@"%@/lucky_gift_streamer.svga", API_Image_URL]; [self.parser parseWithURL:[NSURL URLWithString:anatomiser1Name] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { @kStrongify(self); self.hidden = NO; self.giftImageView.hidden = NO; self.giftImageView.videoItem = videoItem; self.giftImageView.loops = 1; self.giftImageView.clearsAfterStop = YES; [self.giftImageView startAnimation]; } failureBlock:^(NSError * _Nonnull error) { }]; } } - (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; } @end