@@ -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 < GiftReceive InfoModel * > * giftEffectQueue ;
// / 复 用 池
@ property ( strong , nonatomic ) NSMutableSet * bannerDequePool ;
// / 可 见 池
@ property ( strong , nonatomic ) NSMutableSet * bannerVisiablePool ;
// / 礼 物 定 时 器 6 s 刷 新 一 次
@ 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 . g iftEffectQueue addObject : obj ] ;
GiftReceiveInfoModel * model = [ [ G iftReceiveInfoModel 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 秒 是 1 、 单 纯 的 svga 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 . low LevelView addSubview : self . giftEffectView ] ;
[ self . middle LevelView 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 < GiftReceive InfoModel * > * ) 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 ;
}