feat: 完成礼物连击功能 | 更换金币资源图片
This commit is contained in:
@@ -65,7 +65,9 @@
|
||||
#import "PIRoomGiftBroadcastWindow.h"
|
||||
#import "PIUniversalBannerModel.h"
|
||||
#import "PIUniversalBannerView.h"
|
||||
#import "GiftComboFlagView.h"
|
||||
|
||||
#import "GiftComboManager.h"
|
||||
|
||||
@interface XPRoomAnimationView ()<SVGAPlayerDelegate,NIMBroadcastManagerDelegate, XPRoomGiftBroadcastViewDelegate, HWDMP4PlayDelegate, XPRoomLuckyBigPrizeViewDelegate, XPRoomGraffitiGiftAnimationViewDelegate, XPRoomStarKitchenBannerViewDelegate,PAGViewListener,XPRoomAnchorRankBannerViewDelegate,PIRoomGiftBroadcastWindowDelegate,PIUniversalBannerViewDelegate>
|
||||
///展示的不同层级
|
||||
@@ -268,7 +270,7 @@
|
||||
if (attachment.first == CustomMessageType_Gift) {
|
||||
GiftReceiveInfoModel * receiveInfo = [GiftReceiveInfoModel modelWithJSON:attachment.data];
|
||||
receiveInfo.isLuckyBagGift = attachment.second == Custom_Message_Sub_Gift_LuckySend;
|
||||
receiveInfo.isBatch = YES;
|
||||
receiveInfo.isBatch = (attachment.second == Custom_Message_Sub_AllBatchSend || attachment.second == Custom_Message_Sub_AllBatchMicroLuckySend);
|
||||
[self receiveGiftHandleSendGiftAnimation:attachment];
|
||||
if (receiveInfo.isLuckyBagGift) {
|
||||
if (!self.delegate.getRoomInfo.hasAnimationEffect) {return;}
|
||||
@@ -292,7 +294,7 @@
|
||||
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 receiveGiftHandleSendGiftAnimation:attachment];
|
||||
if (receiveInfo.isLuckyBagGift) {
|
||||
if (!self.delegate.getRoomInfo.hasAnimationEffect) {return;}
|
||||
if (receiveInfo.viewUrl.length > 0) {
|
||||
@@ -303,7 +305,6 @@
|
||||
if (luckyGiftSvgaUrl.absoluteString.length > 0) {
|
||||
[self playLuckyGiftEffect:luckyGiftSvgaUrl];
|
||||
}
|
||||
|
||||
}
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self receiveGift:receiveInfo];
|
||||
@@ -1500,8 +1501,18 @@
|
||||
}
|
||||
endPoint = [self getGiftAnimationPoint:userId isEnd:YES];
|
||||
dispatch_time_t timer = dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC);
|
||||
|
||||
BOOL isCombing = [[GiftComboManager sharedManager] isGiftCombing] &&
|
||||
[sendUid isEqualToString:[AccountInfoStorage instance].getUid];
|
||||
|
||||
if (isCombing) {
|
||||
timer = dispatch_time(DISPATCH_TIME_NOW, 0.25 * NSEC_PER_SEC);
|
||||
}
|
||||
dispatch_after(timer, dispatch_get_main_queue(), ^{
|
||||
[self beginGiftAnimation:giftInfo.giftUrl startPoint:starPoint endPoint:endPoint];
|
||||
[self beginGiftAnimation:giftInfo.giftUrl
|
||||
startPoint:starPoint
|
||||
endPoint:endPoint
|
||||
isGiftCombing:isCombing];
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1517,10 +1528,20 @@
|
||||
point = CGPointMake([UIScreen mainScreen].bounds.size.width / 2, 44 + kSafeAreaTopHeight);
|
||||
}
|
||||
}
|
||||
|
||||
if ([[GiftComboManager sharedManager] isGiftCombing] &&
|
||||
[uid isEqualToString:[AccountInfoStorage instance].getUid] &&
|
||||
isEnd == false) {
|
||||
point = CGPointMake([UIScreen mainScreen].bounds.size.width - 60, [UIScreen mainScreen].bounds.size.height - kSafeAreaTopHeight - 60);
|
||||
}
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
- (void)beginGiftAnimation:(NSString *)giftUrl startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint {
|
||||
- (void)beginGiftAnimation:(NSString *)giftUrl
|
||||
startPoint:(CGPoint)startPoint
|
||||
endPoint:(CGPoint)endPoint
|
||||
isGiftCombing:(BOOL)isGiftCombing {
|
||||
NetImageView * giftImageView = [self.giftReuseArray anyObject];
|
||||
if (giftImageView == nil) {
|
||||
giftImageView = [[NetImageView alloc]initWithFrame:CGRectMake(0, 0 , 55, 55)];
|
||||
@@ -1536,14 +1557,61 @@
|
||||
giftImageView.imageUrl = giftUrl;
|
||||
[self.lowLevelView addSubview:giftImageView];
|
||||
CAAnimationGroup *group = [self createGiftAnimationStartPoint:startPoint endPoint:endPoint];
|
||||
if (isGiftCombing) {
|
||||
group = [self createGiftComboAnimationStartPoint:startPoint endPoint:endPoint];
|
||||
}
|
||||
// 确保视图在动画开始前设置到 startPoint 位置
|
||||
giftImageView.layer.position = startPoint;
|
||||
[giftImageView.layer addAnimation:group forKey:@"giftDisplayViewAnimation"];
|
||||
[self performSelector:@selector(aniationDidFinish:) withObject:giftImageView afterDelay:(3.2+0.25)];
|
||||
}
|
||||
|
||||
- (CAAnimationGroup *)createGiftComboAnimationStartPoint:(CGPoint)startPoint
|
||||
endPoint:(CGPoint)endPoint {
|
||||
// 缩放动画1: 动画开始时缩放至 0.4
|
||||
CAKeyframeAnimation *scaleAnimation1 = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
|
||||
scaleAnimation1.duration = 0.1;
|
||||
scaleAnimation1.values = @[@1.0, @0.4];
|
||||
scaleAnimation1.repeatCount = 1;
|
||||
scaleAnimation1.calculationMode = kCAAnimationCubic;
|
||||
scaleAnimation1.removedOnCompletion = NO;
|
||||
scaleAnimation1.fillMode = kCAFillModeForwards;
|
||||
|
||||
// 位移动画: 0.5秒内从起点移动到目标点
|
||||
CAKeyframeAnimation *positionAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
|
||||
positionAnimation.duration = 0.5;
|
||||
positionAnimation.beginTime = 0.1; // 缩放结束后开始位移
|
||||
positionAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
|
||||
positionAnimation.values = @[[NSValue valueWithCGPoint:startPoint], [NSValue valueWithCGPoint:endPoint]];
|
||||
positionAnimation.repeatCount = 1;
|
||||
positionAnimation.removedOnCompletion = NO;
|
||||
positionAnimation.fillMode = kCAFillModeForwards;
|
||||
|
||||
// 缩放动画2: 在位移的过程中逐渐变大到 1.2
|
||||
CAKeyframeAnimation *scaleAnimation2 = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
|
||||
scaleAnimation2.duration = 0.5;
|
||||
scaleAnimation2.beginTime = 0.1; // 同时与位移动画进行
|
||||
scaleAnimation2.values = @[@0.4, @2];
|
||||
scaleAnimation2.repeatCount = 1;
|
||||
scaleAnimation2.calculationMode = kCAAnimationCubic;
|
||||
scaleAnimation2.removedOnCompletion = NO;
|
||||
scaleAnimation2.fillMode = kCAFillModeForwards;
|
||||
|
||||
// 创建动画组
|
||||
CAAnimationGroup *group = [CAAnimationGroup animation];
|
||||
group.duration = 0.6; // 总时间为 0.1 (缩放) + 0.5 (位移与缩放)
|
||||
group.animations = @[scaleAnimation1, positionAnimation, scaleAnimation2];
|
||||
group.repeatCount = 1;
|
||||
group.removedOnCompletion = NO;
|
||||
group.fillMode = kCAFillModeForwards;
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
/// 图片运动的动画组
|
||||
/// @param startPoint 开始的点
|
||||
/// @param endPoint 结束的点
|
||||
- (CAAnimationGroup *)createGiftAnimationStartPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint{
|
||||
- (CAAnimationGroup *)createGiftAnimationStartPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint {
|
||||
CGPoint centerPoint = CGPointMake(KScreenWidth / 2, KScreenHeight / 2);
|
||||
CAKeyframeAnimation *animation0 = [CAKeyframeAnimation animation];
|
||||
animation0.duration = 0.8;
|
||||
@@ -1563,8 +1631,7 @@
|
||||
animation1.calculationMode = kCAAnimationCubic;
|
||||
animation1.removedOnCompletion = NO;
|
||||
animation1.fillMode = kCAFillModeForwards;
|
||||
|
||||
|
||||
|
||||
CAKeyframeAnimation *animation2 = [CAKeyframeAnimation animation];
|
||||
animation2.duration = 0.8;
|
||||
animation2.beginTime = 0.8;
|
||||
@@ -1853,11 +1920,53 @@
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - 连击效果
|
||||
- (void)receiveCombo:(GiftReceiveInfoModel *)receiveInfo {
|
||||
[[GiftComboManager sharedManager] receiveGiftInfoForDisplayComboFlags:receiveInfo
|
||||
container:self];
|
||||
}
|
||||
|
||||
- (void)startAnimation:(UIView *)animatedView {
|
||||
// 计算屏幕左边的目标位置
|
||||
CGFloat leftPosition = -animatedView.frame.size.width;
|
||||
|
||||
// 动画步骤1:从屏幕右边移入屏幕中间
|
||||
[UIView animateWithDuration:0.25
|
||||
delay:0
|
||||
options:UIViewAnimationOptionCurveEaseInOut
|
||||
animations:^{
|
||||
// 将视图移动到屏幕的中间左侧位置
|
||||
animatedView.center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
|
||||
} completion:^(BOOL finished) {
|
||||
// 停顿 2 秒后,继续动画移出屏幕左侧
|
||||
[self continueAnimationToLeft:leftPosition view:animatedView];
|
||||
}];
|
||||
}
|
||||
|
||||
// 动画步骤2:移出到屏幕左边
|
||||
- (void)continueAnimationToLeft:(CGFloat)leftPosition view:(UIView *)animatedView {
|
||||
// 停顿 2 秒后开始动画
|
||||
[UIView animateWithDuration:0.25
|
||||
delay:500.0
|
||||
options:UIViewAnimationOptionCurveEaseInOut
|
||||
animations:^{
|
||||
// 将视图移出屏幕左侧
|
||||
animatedView.center = CGPointMake(leftPosition, self.bounds.size.height / 2);
|
||||
} completion:^(BOOL finished) {
|
||||
// 移除视图,释放内存
|
||||
[animatedView removeFromSuperview];
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - 普通礼物
|
||||
///收到了礼物
|
||||
- (void)receiveGift:(GiftReceiveInfoModel *)receiveInfo {
|
||||
if ([self isInSudGame]) {return;}
|
||||
if(receiveInfo.isHomeShow == YES)return;
|
||||
if ([self isInSudGame] || receiveInfo.isHomeShow == YES) {
|
||||
return;
|
||||
}
|
||||
|
||||
[self receiveCombo:receiveInfo];
|
||||
|
||||
///CPU警告的时候 需要停止接收动画
|
||||
RoomInfoModel * roomInfo = [self.delegate getRoomInfo];
|
||||
if (receiveInfo.isLuckyBagGift) {
|
||||
|
Reference in New Issue
Block a user