修改了特效和横幅不同步的问题

This commit is contained in:
fengshuo
2021-11-19 12:06:39 +08:00
parent 561be65b49
commit cc0eb1e85b
5 changed files with 164 additions and 95 deletions

View File

@@ -93,15 +93,17 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, strong)NSString *avatar;
///送礼物的个数
@property (assign, nonatomic) NSInteger giftNum;
/** 礼物名字 */
///礼物名字
@property (nonatomic, strong)NSString *giftName;
/** 非全麦 多人送礼时 */
///动效url
@property (copy, nonatomic) NSString *vggUrl;
///非全麦 多人送礼时
@property (nonatomic, strong) NSArray<GiftReceiveUserInfoModel *> *targetUsers;
/** 福袋礼物需要展示的vg动画 */
///福袋礼物需要展示的vg动画
@property (nonatomic, strong) NSArray<GiftInfoModel *> *displayGift;
///福袋随机获取的礼物
@property (nonatomic, strong) NSArray <GiftLuckyBagGiftsInfo *> *luckyBagGifts;
//多人接收到的具体福袋礼物 是对luckyBagGifts的分离 要多次发送消息使用
///多人接收到的具体福袋礼物 是对luckyBagGifts的分离 要多次发送消息使用
@property (nonatomic, strong) GiftLuckyBagGiftsInfo* luckyGiftList;
///礼物来源
@property (nonatomic,assign) GiftSourceType sourceType;

View File

@@ -30,7 +30,7 @@
#import "XPRoomGiftBannerView.h"
#import "XPRoomGiftBroadcastView.h"
@interface XPRoomBackContainerView ()<SVGAPlayerDelegate, NIMChatManagerDelegate,NIMBroadcastManagerDelegate>
@interface XPRoomBackContainerView ()<SVGAPlayerDelegate, NIMChatManagerDelegate,NIMBroadcastManagerDelegate, XPRoomGiftBroadcastViewDelegate>
///
///
@property (nonatomic,strong) UIView * lowLevelView;
@@ -47,16 +47,13 @@
///
@property (nonatomic,weak) id<RoomHostDelegate>delegate;
///
@property (nonatomic,strong) NSMutableArray<GiftInfoModel *> *giftEffectQueue;
///
@property (nonatomic,assign) BOOL isGiftEffectPlaying;
///520
@property (nonatomic,strong) NSMutableArray<GiftReceiveInfoModel *> *giftBannerQueue;;
@property (nonatomic,strong) NSMutableArray<GiftReceiveInfoModel *> *giftEffectQueue;
///
@property (strong,nonatomic)NSMutableSet * bannerDequePool;
///
@property (strong,nonatomic)NSMutableSet * bannerVisiablePool;
/// 6s
@property (nonatomic,strong)dispatch_source_t giftEffectTimer;
///
@property (nonatomic,strong) NSMutableArray<XPGiftBigPrizeModel *> *bigPrizeGiftQueue;
@@ -171,10 +168,10 @@
- (void)createGiftBroadcastViewAnimation:(XPRoomGiftBroadCastModel *)giftModel {
XPRoomGiftBroadcastView * view = [[XPRoomGiftBroadcastView alloc] init];
view.frame = CGRectMake(KScreenWidth, 35 + statusbarHeight, KScreenWidth, 200);
view.delegate = self;
view.frame = CGRectMake(KScreenWidth, 35 + statusbarHeight, KScreenWidth, 150);
view.broadcastModel = giftModel;
[self.highLevleView addSubview:view];
[self beginGiftBraodcastViewAnimation:view notifyStaySecond:giftModel.notifyStaySecond];
}
@@ -215,6 +212,21 @@
[view pop_addAnimation:moveAnimation forKey:@"moveOutAnimation"];
}
#pragma mark - XPRoomGiftBroadcastViewDelegate
- (void)xPRoomGiftBroadcastView:(XPRoomGiftBroadcastView *)view enterRoom:(NSString *)roomUid {
/// TODO: 退
}
- (void)xPRoomGiftBroadcastView:(XPRoomGiftBroadcastView *)view didClickClose:(XPRoomGiftBroadCastModel *)broadcastModel {
[view removeFromSuperview];
if ([self.giftBroadcastQueue containsObject:broadcastModel]) {
[self.giftBroadcastQueue removeObject:broadcastModel];
}
if (self.giftBroadcastQueue.count > 0) {
[self createGiftBroadcastViewAnimation:self.giftBroadcastQueue.firstObject];
}
}
#pragma mark -
- (void)receiveLuckyGiftBigPrize:(AttachmentModel *)attachment {
if (attachment.second == Custom_Message_Sub_Room_Gift_LuckBag || attachment.second == Custom_Message_Sub_Room_Gift_LuckBag_Server) {
@@ -326,28 +338,21 @@
if (receiveInfo.displayGift.count > 0) {
[receiveInfo.displayGift enumerateObjectsUsingBlock:^(GiftInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.hasVggPic && roomInfor.hasAnimationEffect) {
[self.giftEffectQueue addObject:obj];
GiftReceiveInfoModel * model = [[GiftReceiveInfoModel alloc] init];
model.vggUrl = obj.vggUrl;
[self.giftEffectQueue addObject:model];
}
}];
if (!self.isGiftEffectPlaying && self.giftEffectQueue.count > 0) {
GiftInfoModel * displayInfo = [self.giftEffectQueue firstObject];
[self playGiftEffect:displayInfo];
}
}
} else {
GiftInfoModel *giftInfo = receiveInfo.gift == nil ? receiveInfo.gift : receiveInfo.giftInfo;
if (!giftInfo) {
giftInfo = [[XPGiftStorage shareStorage] findGiftInfo: receiveInfo.giftId];
}
if (giftInfo.hasVggPic && roomInfor.hasAnimationEffect) {
[self.giftEffectQueue addObject:giftInfo];
if (!self.isGiftEffectPlaying && self.giftEffectQueue.count > 0) {
GiftInfoModel * displayInfo = [self.giftEffectQueue firstObject];
[self playGiftEffect:displayInfo];
}
///
if (giftInfo) {
receiveInfo.gift = giftInfo;
}
if (receiveInfo.targetUsers.count > 0 && receiveInfo.targetUids.count <= 0) {
receiveInfo.targetUids = [receiveInfo.targetUsers valueForKeyPath:@"uid"];
}
@@ -361,39 +366,92 @@
///
if (giftTotal >= 520) {
if (self.giftBannerQueue.count == 0) {
[self createGiftBannerViewAnimation:receiveInfo];//
///
[self.giftEffectQueue addObject:receiveInfo];
} else {
///SVGA
if (giftInfo.hasVggPic && roomInfor.hasAnimationEffect) {
receiveInfo.vggUrl = giftInfo.vggUrl;
[self.giftEffectQueue addObject:receiveInfo];
}
[self.giftBannerQueue addObject:receiveInfo];
}
}
if (self.giftEffectTimer == nil && self.giftEffectQueue.count > 0) {
[self startHandleGiftEffectTimer];
}
}
- (void)createGiftBannerViewAnimation:(GiftReceiveInfoModel *)receiveInfo {
__block XPRoomGiftBannerView *view = [self.bannerDequePool anyObject];
if (view == nil) {
view = [[XPRoomGiftBannerView alloc] init];
[self.bannerVisiablePool addObject:view];
}else{
[self.bannerDequePool removeObject:view];
}
[view configGiftBanner:receiveInfo users:[self makeBannerUsers]];
view.frame = CGRectMake(KScreenWidth, 100, KScreenWidth, 153);
[self.lowLevelView addSubview:view];
POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];
springAnimation.springSpeed = 12;
springAnimation.springBounciness = 10.f;
springAnimation.fromValue = [NSValue valueWithCGPoint:view.center];
springAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(view.frame.size.width / 2, view.center.y)];
///
- (void)startHandleGiftEffectTimer {
NSTimeInterval period = 6.0; // 6 1svga 2.svga 3
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), period * NSEC_PER_SEC, 0); //
@kWeakify(self);
[springAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
@kStrongify(self);
if (finished) {
[self removeAnimation:view];
dispatch_source_set_event_handler(_timer, ^{
@kStrongify(self)
if (self.giftEffectQueue.count > 0) {
dispatch_sync(dispatch_get_main_queue(), ^{
GiftReceiveInfoModel * receiveModel = [self.giftEffectQueue firstObject];
[self createGiftBannerViewAnimation:receiveModel];
[self.giftEffectQueue removeObject:receiveModel];
});
}else {
dispatch_source_cancel(_timer);
self.giftEffectTimer = nil;
}
}];
[view pop_addAnimation:springAnimation forKey:@"spingOutAnimation"];
});
dispatch_resume(_timer);
self.giftEffectTimer = _timer;
}
- (void)createGiftBannerViewAnimation:(GiftReceiveInfoModel *)receiveInfo {
GiftInfoModel * giftInfo = receiveInfo.gift;
NSInteger giftTotal = 0;
if (receiveInfo.targetUids.count > 0) {
giftTotal = receiveInfo.giftNum * giftInfo.goldPrice * receiveInfo.targetUids.count;
} else {
giftTotal = receiveInfo.giftNum * giftInfo.goldPrice;
}
if (giftTotal >= 520) {
__block XPRoomGiftBannerView *view = [self.bannerDequePool anyObject];
if (view == nil) {
view = [[XPRoomGiftBannerView alloc] init];
[self.bannerVisiablePool addObject:view];
}else{
[self.bannerDequePool removeObject:view];
}
[self removeGiftBannerView:view];
[view configGiftBanner:receiveInfo users:[self makeBannerUsers]];
view.frame = CGRectMake(KScreenWidth, 100, KScreenWidth, 153);
[self.lowLevelView addSubview:view];
POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];
springAnimation.springSpeed = 12;
springAnimation.springBounciness = 10.f;
springAnimation.fromValue = [NSValue valueWithCGPoint:view.center];
springAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(view.frame.size.width / 2, view.center.y)];
@kWeakify(self);
[springAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
@kStrongify(self);
if (finished) {
[self removeAnimation:view];
}
}];
[springAnimation setAnimationDidStartBlock:^(POPAnimation *anim) {
@kStrongify(self);
if (giftInfo.hasVggPic && [self.delegate getRoomInfo].hasAnimationEffect) {
[self playGiftEffect:giftInfo.vggUrl];
}
}];
[view pop_addAnimation:springAnimation forKey:@"spingOutAnimation"];
} else {
if (receiveInfo.vggUrl.length > 0) {///
[self playGiftEffect:receiveInfo.vggUrl];
}
}
}
//
@@ -405,20 +463,6 @@
moveAnimation.duration = 0.5;
moveAnimation.repeatCount = 1;
moveAnimation.removedOnCompletion = YES;
@kWeakify(self);
[moveAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
@kStrongify(self);
if (finished) {
[self.giftBannerQueue removeObjectAtIndex:0];
if (self.giftBannerQueue.count > 0) {
[self createGiftBannerViewAnimation:self.giftBannerQueue.firstObject];
}
[view removeFromSuperview];
[view resetData];
[self.bannerVisiablePool removeObject:view];
[self.bannerDequePool addObject:view];
}
}];
[view pop_addAnimation:moveAnimation forKey:@"moveOutAnimation"];
}
@@ -436,18 +480,17 @@
/// SVGA
- (void)playGiftEffect:(GiftInfoModel *)giftInfo {
self.isGiftEffectPlaying = YES;
- (void)playGiftEffect:(NSString *)vggUrl {
self.giftEffectView.hidden = NO;
if (self.giftEffectView.superview == nil) {
[self.lowLevelView addSubview:self.giftEffectView];
[self.middleLevelView addSubview:self.giftEffectView];
[self.giftEffectView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.lowLevelView);
make.width.mas_equalTo(KScreenWidth);
make.height.mas_equalTo(KScreenHeight);
}];
}
[self.parser parseWithURL:[NSURL URLWithString:giftInfo.vggUrl] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
[self.parser parseWithURL:[NSURL URLWithString:vggUrl] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
if (videoItem != nil) {
CGFloat width = videoItem.videoSize.width;
CGFloat height = videoItem.videoSize.height;
@@ -470,21 +513,26 @@
} failureBlock:^(NSError * _Nullable error) {
}];
[self.giftEffectQueue removeObject:giftInfo];
}
#pragma mark - SVGAPlayerDelegate
///veiw
- (void)removeGiftBannerView:(XPRoomGiftBannerView *)view {
[view removeFromSuperview];
[view resetData];
[self.bannerVisiablePool removeObject:view];
[self.bannerDequePool addObject:view];
///svga
[self.giftEffectView stopAnimation];
self.giftEffectView.hidden = YES;
}
#pragma mark -
- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player {
if (player == self.giftEffectView) {
self.giftEffectView.hidden = YES;
self.isGiftEffectPlaying = NO;
if (self.giftEffectQueue.count > 0) {
GiftInfoModel * infor = [self.giftEffectQueue firstObject];
[self playGiftEffect:infor];
}
}
}
#pragma mark - Getters And Setters
- (UIImageView *)backImageView {
if (!_backImageView) {
@@ -515,7 +563,7 @@
return _parser;
}
- (NSMutableArray<GiftInfoModel *> *)giftEffectQueue {
- (NSMutableArray<GiftReceiveInfoModel *> *)giftEffectQueue {
if (!_giftEffectQueue) {
_giftEffectQueue = [NSMutableArray array];
}
@@ -529,13 +577,6 @@
return _bigPrizeGiftQueue;
}
- (NSMutableArray<GiftReceiveInfoModel *> *)giftBannerQueue {
if (!_giftBannerQueue) {
_giftBannerQueue = [NSMutableArray array];
}
return _giftBannerQueue;
}
- (NSMutableArray<XPRoomGiftBroadCastModel *> *)giftBroadcastQueue {
if (!_giftBroadcastQueue) {
_giftBroadcastQueue = [NSMutableArray array];
@@ -560,6 +601,7 @@
if (!_lowLevelView) {
_lowLevelView = [[UIView alloc] init];
_lowLevelView.backgroundColor = [UIColor clearColor];
_lowLevelView.userInteractionEnabled = NO;
}
return _lowLevelView;
}
@@ -568,6 +610,7 @@
if (!_middleLevelView) {
_middleLevelView = [[UIView alloc] init];
_middleLevelView.backgroundColor = [UIColor clearColor];
_middleLevelView.userInteractionEnabled = NO;
}
return _middleLevelView;
}
@@ -576,6 +619,7 @@
if (!_highLevleView) {
_highLevleView = [[UIView alloc] init];
_highLevleView.backgroundColor = [UIColor clearColor];
_highLevleView.userInteractionEnabled = NO;
}
return _highLevleView;
}

View File

@@ -8,10 +8,8 @@
#import "XPRoomGiftBannerView.h"
///Third
#import <Masonry/Masonry.h>
#import <pop/pop.h>
///Tool
#import "ThemeColor+Room.h"
#import "XPGiftStorage.h"
///Model
#import "GiftReceiveInfoModel.h"
#import "GiftInfoModel.h"
@@ -128,7 +126,6 @@
[self.backImageView addSubview:self.lightImageView];
[self.backImageView addSubview:self.giftView];
[self.backImageView addSubview:self.giftCountLabel];
[self startLightCircleAnimation];
}
- (void)initSubViewConstraints {
@@ -188,15 +185,14 @@
self.giftView.avatImageView.image = nil;
self.giftView.nickLabel.text = nil;
self.giftCountLabel.text = nil;
[self.lightImageView stopAnimating];
}
- (void)configGiftBanner:(GiftReceiveInfoModel *)receiveInfo users:(NSArray<XPGiftBannerUserInfoModel *> *)users {
if (receiveInfo) {
[self startLightCircleAnimation];
NSInteger giftTotal = 0;
GiftInfoModel *giftInfo = receiveInfo.gift == nil ? receiveInfo.giftInfo : receiveInfo.gift;
if (!giftInfo) {
giftInfo = [[XPGiftStorage shareStorage] findGiftInfo:receiveInfo.giftId];
}
GiftInfoModel *giftInfo = receiveInfo.gift;
self.sendView.avatImageView.imageUrl = receiveInfo.avatar;
self.sendView.nickLabel.text = receiveInfo.nick;

View File

@@ -8,10 +8,22 @@
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class XPRoomGiftBroadCastModel;
@class XPRoomGiftBroadCastModel, XPRoomGiftBroadcastView;
@protocol XPRoomGiftBroadcastViewDelegate <NSObject>
/// 点击了关闭
- (void)xPRoomGiftBroadcastView:(XPRoomGiftBroadcastView *)view didClickClose:(XPRoomGiftBroadCastModel *)broadcastModel;
///点击了进入房间
- (void)xPRoomGiftBroadcastView:(XPRoomGiftBroadcastView *)view enterRoom:(NSString *)roomUid;
@end
@interface XPRoomGiftBroadcastView : UIView
///
@property (nonatomic,strong) XPRoomGiftBroadCastModel *broadcastModel;
///代理
@property (nonatomic,weak) id<XPRoomGiftBroadcastViewDelegate> delegate;
@end
NS_ASSUME_NONNULL_END

View File

@@ -127,13 +127,23 @@
if (self) {
[self initSubViews];
[self initSubViewConstraints];
[self initEvents];
}
return self;
}
#pragma mark - Response
- (void)closeButtonAction:(UIButton *)sender {
[self removeFromSuperview];
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomGiftBroadcastView:didClickClose:)]) {
[self.delegate xPRoomGiftBroadcastView:self didClickClose:self.broadcastModel];
}
}
- (void)didClickEnterRoom {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomGiftBroadcastView:enterRoom:)]) {
[self.delegate xPRoomGiftBroadcastView:self enterRoom:[NSString stringWithFormat:@"%ld", self.broadcastModel.roomUid]];
}
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.backImageView];
@@ -180,7 +190,7 @@
}];
[self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.backImageView).offset(-13 * kScreenScale);
make.left.mas_equalTo(self.giftImageView.mas_right).offset(13 * kScreenScale);
make.centerY.mas_equalTo(self.sendView);
}];
@@ -191,6 +201,11 @@
}];
}
- (void)initEvents {
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickEnterRoom)];
[self.backImageView addGestureRecognizer:tap];
}
- (void)updateSubviews:(BroadCastLevel)level {
NSString * nickBackImageName;
UIColor * nickColor;