驾驶座驾进房
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
#import "XPRoomCandyGiftView.h"
|
||||
|
||||
|
||||
@interface XPRoomAnimationView ()<SVGAPlayerDelegate, NIMChatManagerDelegate,NIMBroadcastManagerDelegate, XPRoomGiftBroadcastViewDelegate>
|
||||
@interface XPRoomAnimationView ()<SVGAPlayerDelegate,NIMBroadcastManagerDelegate, XPRoomGiftBroadcastViewDelegate>
|
||||
///展示的不同层级
|
||||
///最底层的
|
||||
@property (nonatomic,strong) XPRoomAnimationHitView * lowLevelView;
|
||||
@@ -74,18 +74,21 @@
|
||||
@property (nonatomic,strong) NSMutableSet<NetImageView *> * giftVisibleArray;
|
||||
///糖果树礼物的队列
|
||||
@property (nonatomic,strong) NSMutableArray *candyTreegiftQueue;
|
||||
#pragma mark - 进房动画的
|
||||
@property (nonatomic, strong) NSMutableArray<NSString *> *carEffectQueue;
|
||||
@property (nonatomic,strong) SVGAImageView *carEffectView;
|
||||
@end
|
||||
|
||||
@implementation XPRoomAnimationView
|
||||
|
||||
- (void)dealloc {
|
||||
[NSObject cancelPreviousPerformRequestsWithTarget:self];
|
||||
[[NIMSDK sharedSDK].broadcastManager removeDelegate:self];
|
||||
}
|
||||
|
||||
- (instancetype)initWithdelegate:(id<RoomHostDelegate>)delegate {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
[[NIMSDK sharedSDK].chatManager addDelegate:self];
|
||||
[[NIMSDK sharedSDK].broadcastManager addDelegate:self];
|
||||
self.delegate = delegate;
|
||||
[self initSubViews];
|
||||
@@ -114,13 +117,6 @@
|
||||
make.edges.mas_equalTo(self);
|
||||
}];
|
||||
}
|
||||
#pragma mark - NIMChatManagerDelegate
|
||||
- (void)onRecvMessages:(NSArray<NIMMessage *> *)messages {
|
||||
for (NIMMessage * message in messages) {
|
||||
[self handleMessage:message];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - NIMBroadcastDelegate
|
||||
// 广播消息
|
||||
- (void)onReceiveBroadcastMessage:(NIMBroadcastMessage *)broadcastMessage{
|
||||
@@ -132,36 +128,71 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//发送消息成功回调
|
||||
- (void)sendMessage:(NIMMessage *)message didCompleteWithError:(NSError *)error {
|
||||
[self handleMessage:message];
|
||||
#pragma mark - RoomGuestDelegate
|
||||
- (void)handleNIMCustomMessage:(AttachmentModel *)attachment {
|
||||
if (attachment.first == CustomMessageType_Gift) {
|
||||
GiftReceiveInfoModel * receiveInfo = [GiftReceiveInfoModel modelWithJSON:attachment.data];
|
||||
receiveInfo.isLuckyBagGift = attachment.second == Custom_Message_Sub_Gift_LuckySend;
|
||||
receiveInfo.isBatch = YES;
|
||||
[self receiveGiftHandleSendGiftAnimation:attachment];
|
||||
[self receiveGift:receiveInfo];
|
||||
} else if (attachment.first == CustomMessageType_AllMicroSend) { //发送全麦礼物 或者多人礼物
|
||||
GiftReceiveInfoModel * receiveInfo = [GiftReceiveInfoModel modelWithJSON:attachment.data];
|
||||
receiveInfo.isLuckyBagGift = (attachment.second == Custom_Message_Sub_AllMicroLuckySend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend);
|
||||
receiveInfo.isBatch = (attachment.second == Custom_Message_Sub_AllBatchSend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend);
|
||||
[self receiveGiftHandleSendGiftAnimation:attachment];
|
||||
[self receiveGift:receiveInfo];
|
||||
} else if (attachment.first == CustomMessageType_LuckyBag) {//福袋消息厅内展示
|
||||
[self receiveLuckyGiftBigPrize:attachment];
|
||||
} else if (attachment.first == CustomMessageType_Candy_Tree && (attachment.second == Custom_Message_Sub_Candy_Tree_InRoom_NeedAllMicSend || attachment.second == Custom_Message_Sub_Candy_Tree_AllRoom_Notify) ) {//糖果树
|
||||
[self receiveCandyTreeGiftHighLevle:attachment];
|
||||
} else if (attachment.first == CustomMessageType_Car_Notify && attachment.second == Custom_Message_Sub_Car_EnterRoom ) {//座驾进房
|
||||
[self receiveDriveCarEnterRoom:attachment];
|
||||
}
|
||||
}
|
||||
#pragma mark - 座驾的动画
|
||||
- (void)receiveDriveCarEnterRoom:(AttachmentModel *)attatchment {
|
||||
NSString * effect = attatchment.data[@"effect"];
|
||||
if (effect.length <= 0) return;
|
||||
if (self.carEffectQueue.count == 0) {
|
||||
[self playCarEffect:effect];
|
||||
return;
|
||||
}
|
||||
[self.carEffectQueue addObject:effect];
|
||||
}
|
||||
|
||||
- (void)handleMessage:(NIMMessage *)message {
|
||||
if (message.session.sessionType == NIMSessionTypeChatroom && message.messageType == NIMMessageTypeCustom) {
|
||||
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
|
||||
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
|
||||
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
|
||||
if (attachment.first == CustomMessageType_Gift) {
|
||||
GiftReceiveInfoModel * receiveInfo = [GiftReceiveInfoModel modelWithJSON:attachment.data];
|
||||
receiveInfo.isLuckyBagGift = attachment.second == Custom_Message_Sub_Gift_LuckySend;
|
||||
receiveInfo.isBatch = YES;
|
||||
[self receiveGiftHandleSendGiftAnimation:attachment];
|
||||
[self receiveGift:receiveInfo];
|
||||
} else if (attachment.first == CustomMessageType_AllMicroSend) { //发送全麦礼物 或者多人礼物
|
||||
GiftReceiveInfoModel * receiveInfo = [GiftReceiveInfoModel modelWithJSON:attachment.data];
|
||||
receiveInfo.isLuckyBagGift = (attachment.second == Custom_Message_Sub_AllMicroLuckySend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend);
|
||||
receiveInfo.isBatch = (attachment.second == Custom_Message_Sub_AllBatchSend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend);
|
||||
[self receiveGiftHandleSendGiftAnimation:attachment];
|
||||
[self receiveGift:receiveInfo];
|
||||
} else if (attachment.first == CustomMessageType_LuckyBag) {//福袋消息厅内展示
|
||||
[self receiveLuckyGiftBigPrize:attachment];
|
||||
} else if (attachment.first == CustomMessageType_Candy_Tree && (attachment.second == Custom_Message_Sub_Candy_Tree_InRoom_NeedAllMicSend || attachment.second == Custom_Message_Sub_Candy_Tree_AllRoom_Notify)) {//糖果树
|
||||
[self receiveCandyTreeGiftHighLevle:attachment];
|
||||
}
|
||||
}
|
||||
- (void)playCarEffect:(NSString *)carEffect {
|
||||
if (self.carEffectView.superview == nil) {
|
||||
[self.middleLevelView addSubview:self.carEffectView];
|
||||
[self.carEffectView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.center.mas_equalTo(self.middleLevelView);
|
||||
make.width.mas_equalTo(KScreenWidth);
|
||||
make.height.mas_equalTo(KScreenHeight);
|
||||
}];
|
||||
}
|
||||
[self.parser parseWithURL:[NSURL URLWithString:carEffect] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
|
||||
if (videoItem != nil) {
|
||||
CGFloat width = videoItem.videoSize.width;
|
||||
CGFloat height = videoItem.videoSize.height;
|
||||
if (width > height) {
|
||||
self.giftEffectView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
} else {//高大于宽
|
||||
CGFloat resizeH = KScreenWidth * height / width;//按照屏幕的宽度去缩放,获得高度
|
||||
if (resizeH > KScreenHeight) {//如果大于屏幕高度,填充
|
||||
self.giftEffectView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
} else {//小于屏幕高度,
|
||||
self.giftEffectView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
}
|
||||
}
|
||||
self.carEffectView.alpha = 1;
|
||||
self.carEffectView.loops = 1;
|
||||
self.carEffectView.clearsAfterStop = YES;
|
||||
self.carEffectView.videoItem = videoItem;
|
||||
[self.carEffectView startAnimation];
|
||||
}
|
||||
} failureBlock:^(NSError * _Nullable error) {
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - 糖果树横幅动画
|
||||
@@ -714,7 +745,7 @@
|
||||
if (self.giftEffectView.superview == nil) {
|
||||
[self.middleLevelView addSubview:self.giftEffectView];
|
||||
[self.giftEffectView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.center.mas_equalTo(self.lowLevelView);
|
||||
make.center.mas_equalTo(self.middleLevelView);
|
||||
make.width.mas_equalTo(KScreenWidth);
|
||||
make.height.mas_equalTo(KScreenHeight);
|
||||
}];
|
||||
@@ -758,6 +789,11 @@
|
||||
- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player {
|
||||
if (player == self.giftEffectView) {
|
||||
self.giftEffectView.hidden = YES;
|
||||
} else if(self.carEffectView) {
|
||||
if (self.carEffectQueue.count > 0) {
|
||||
[self playCarEffect:self.carEffectQueue.firstObject];
|
||||
[self.carEffectQueue removeObjectAtIndex:0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -869,4 +905,24 @@
|
||||
return _candyTreegiftQueue;
|
||||
}
|
||||
|
||||
- (NSMutableArray<NSString *> *)carEffectQueue {
|
||||
if (_carEffectQueue == nil) {
|
||||
_carEffectQueue = [NSMutableArray array];
|
||||
}
|
||||
return _carEffectQueue;
|
||||
}
|
||||
|
||||
- (SVGAImageView *)carEffectView {
|
||||
if (_carEffectView == nil) {
|
||||
_carEffectView = [[SVGAImageView alloc]init];
|
||||
_carEffectView.delegate = self;
|
||||
_carEffectView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
_carEffectView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
|
||||
_carEffectView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
|
||||
_carEffectView.alpha = 0;
|
||||
_carEffectView.userInteractionEnabled = NO;
|
||||
}
|
||||
return _carEffectView;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user