try to fix send gift animation problems

This commit is contained in:
edwinQQQ
2024-12-06 21:00:20 +08:00
parent 612b84e47b
commit 8ba4eaf2f5
8 changed files with 164 additions and 69 deletions

View File

@@ -82,6 +82,7 @@ NSString * const kImageTypeMonentsPhoto = @"imageMogr2/auto-orient/thumbnail/400
break;
case ImageTypeUserCardLevel:
configUrl = kImageTypeUserCardLevel;
break;
case ImageTypeMonentsPhoto:
configUrl = kImageTypeMonentsPhoto;
break;

View File

@@ -310,18 +310,8 @@ PIUniversalBannerViewDelegate>
if (attachment.second == Custom_Message_Sub_Gift_EmbeddedStyle) {
if (receiveInfo.giftVo) {
receiveInfo.gift = receiveInfo.giftVo;
// receiveInfo.targetUid = receiveInfo.recvUserUid;
// receiveInfo.targetNick = receiveInfo.recvUserNick;
// receiveInfo.targetUids = @[receiveInfo.recvUserUid];
// if (<#condition#>) {
// <#statements#>
// }
// [data setObject:[[obj objectForKey:@"uid"] stringValue] forKey:@"targetUid"];
// [data setObject:[obj objectForKey:@"nick"] forKey:@"targetNick"];
// [data setObject:[obj objectForKey:@"avatar"] forKey:@"targetAvatar"];
}
// TODO:
receiveInfo.targetUid = [[attachment.data objectForKey:@"recvUserUid"] stringValue];
receiveInfo.targetNick = [attachment.data objectForKey:@"recvUserNick"];
receiveInfo.targetAvatar = [attachment.data objectForKey:@"recvUserAvatar"];
@@ -1751,6 +1741,20 @@ PIUniversalBannerViewDelegate>
}
}
#if DEBUG
for (NSInteger i=0;i<15;i++) {
endPoint = [self.delegate animationPointAtStageViewByIndex:i];
BOOL isCombing = [[GiftComboManager sharedManager] isGiftCombing] && [sendUid isEqualToString:[AccountInfoStorage instance].getUid];
CGFloat time = isCombing ? 0.25 : 0.5;
dispatch_time_t timer = dispatch_time(DISPATCH_TIME_NOW, time * NSEC_PER_SEC);
dispatch_after(timer, dispatch_get_main_queue(), ^{
[self beginGiftAnimation:giftInfo.giftUrl
startPoint:starPoint
endPoint:endPoint
isGiftCombing:isCombing];
});
}
#else
for (NSString *targetUid in targetUids) {
NSString * userId = targetUid;
if ([userId isKindOfClass:[NSNumber class]]) {
@@ -1759,19 +1763,21 @@ PIUniversalBannerViewDelegate>
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];
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
[self beginGiftAnimation:giftInfo.giftUrl
startPoint:starPoint
endPoint:endPoint
endPoint:endPoint
isGiftCombing:isCombing];
});
}
#endif
}
///

View File

@@ -24,6 +24,8 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (CGPoint)animationPointAtStageViewByUid:(NSString *)uid;
- (CGPoint)animationPointAtStageViewByIndex:(NSInteger)index;
@end
NS_ASSUME_NONNULL_END

View File

@@ -22,12 +22,27 @@
@property (nonatomic, assign) NSInteger totalCount;
@property (nonatomic, strong) NSTimer *timer;
@property(nonatomic, copy) NSDictionary *stringAttributes;
@property(nonatomic, copy) NSString *cacheAvatar;
@property(nonatomic, copy) NSString *cacheIcon;
@end
@implementation GiftComboFlagView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowBlurRadius = 3;
shadow.shadowColor = [UIColor colorWithRed:255/255.0 green:153./255.0 blue:0/255.0 alpha:1];
shadow.shadowOffset = CGSizeMake(0,1);
self.stringAttributes = @{NSFontAttributeName: kFontSemibold(30),
NSForegroundColorAttributeName: UIColorFromRGB(0xFFE07B),
NSShadowAttributeName: shadow
};
[self setupUI];
}
return self;
@@ -38,73 +53,109 @@
[self endTimer];
}
- (void)startTimer {
if (_timer) {
[self endTimer];
#pragma mark - UI
- (void)updateUIWithModel:(GiftReceiveInfoModel *)model {
if ([NSString isEmpty:self.cacheIcon]) {
self.cacheIcon = model.gift.giftUrl;
} else {
if ([self.cacheIcon isEqualToString:model.gift.giftUrl]) {
self.cacheIcon = model.gift.giftUrl;
self.giftIcon.imageUrl = model.gift.giftUrl;
}
}
if ([NSString isEmpty:self.cacheAvatar]) {
self.cacheIcon = model.avatar;
self.giftGiverAvatar.imageUrl = model.avatar;
} else {
if (![self.cacheAvatar isEqualToString:model.avatar]) {
self.cacheIcon = model.avatar;
self.giftGiverAvatar.imageUrl = model.avatar;
}
}
self.giftGiverNameLabel.text = model.nick;
self.giftReceiverNameLabel.text = [self receiverNameForModel:model];
NSInteger total = model.comboCount * model.giftNum * model.receiveUserCount;
NSString *countStr = [NSString stringWithFormat:@"x%ld", (long)total];
self.giftCountLabel.attributedText = [self generateAttributedStringForCount:countStr];
}
- (NSMutableAttributedString *)generateAttributedStringForCount:(NSString *)countStr {
return [[NSMutableAttributedString alloc] initWithString:countStr
attributes:self.stringAttributes];
}
- (void)startTimer {
[self endTimer];
@kWeakify(self);
_timer = [NSTimer scheduledTimerWithTimeInterval:5.0 repeats:NO block:^(NSTimer * _Nonnull timer) {
@kStrongify(self);
[self removeFromSuperview];
if (self.timerEnd) {
self.timerEnd();
if (self) {
[self handleTimerFired];
}
}];
//
[[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
- (void)endTimer {
[_timer invalidate];
_timer = nil;
if (self.timer) {
[self.timer invalidate];
self.timer = nil;
}
}
#pragma mark -
- (void)handleTimerFired {
[self removeFromSuperview];
if (self.timerEnd) {
self.timerEnd();
}
}
#pragma mark -
- (void)performCountLabelAnimationWithTotal:(NSInteger)total {
if (self.giftCountLabel.layer.animationKeys.count != 0) {
return;
}
CGFloat scale = 1.1 + (0.01 * total);
scale = MIN(3.0, scale);
self.giftCountLabel.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:0.25 animations:^{
self.giftCountLabel.transform = CGAffineTransformMakeScale(scale, scale);
} completion:^(BOOL finished) {
self.giftCountLabel.transform = CGAffineTransformIdentity;
}];
}
- (void)updateReceiveInfoModel:(GiftReceiveInfoModel *)model
animationType:(NSInteger)type {
_receiveInfo = model;
self.giftGiverAvatar.imageUrl = model.avatar;
self.giftIcon.imageUrl = model.gift.giftUrl;
self.giftGiverNameLabel.text = model.nick;
[self updateUIWithModel:model];
if (model.isComboBatch) {
self.giftReceiverNameLabel.text = YMLocalizedString(@"Combo_1");
} else {
if (model.targetUids.count == 1) {
self.giftReceiverNameLabel.text = model.targetNick;
} else if (model.targetUids.count > 1) {
self.giftReceiverNameLabel.text = YMLocalizedString(@"Combo_2");
} else {
self.giftReceiverNameLabel.text = model.targetNick;
}
}
NSInteger total = model.comboCount * model.giftNum * model.receiveUserCount;
NSString *countStr = [NSString stringWithFormat:@"x%ld", (long)total];
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowBlurRadius = 3;
shadow.shadowColor = [UIColor colorWithRed:255/255.0 green:153./255.0 blue:0/255.0 alpha:1];
shadow.shadowOffset =CGSizeMake(0,1);
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:countStr
attributes: @{NSFontAttributeName: kFontSemibold(30),
NSForegroundColorAttributeName: UIColorFromRGB(0xFFE07B),
NSShadowAttributeName: shadow}];
self.giftCountLabel.attributedText = string;
if (type == 1) {
CGFloat scale = 1.1 + (0.01 * total);
scale = MIN(3.0, scale);
self.giftCountLabel.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:0.25
animations:^{
self.giftCountLabel.transform = CGAffineTransformMakeScale(scale, scale);
} completion:^(BOOL finished) {
self.giftCountLabel.transform = CGAffineTransformIdentity;
}];
[self performCountLabelAnimationWithTotal:model.comboCount * model.giftNum * model.receiveUserCount];
}
[self startTimer];
}
- (NSString *)receiverNameForModel:(GiftReceiveInfoModel *)model {
if (model.isComboBatch) {
return YMLocalizedString(@"Combo_1");
}
if (model.targetUids.count > 1) {
return YMLocalizedString(@"Combo_2");
}
return model.targetNick;
}
- (void)setupUI {
[self addSubview:self.backgroundImageView];
[self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -179,9 +230,7 @@
if (!_giftIcon) {
_giftIcon = [[NetImageView alloc] init];
_giftIcon.contentMode = UIViewContentModeScaleAspectFit;
// _giftIcon.layer.cornerRadius = kGetScaleWidth(24);
_giftIcon.layer.masksToBounds = YES;
_giftIcon.clipsToBounds = YES;
[_giftIcon setCornerRadius:kGetScaleWidth(24)];
}
return _giftIcon;
}
@@ -207,7 +256,6 @@
return _giftReceiverNameLabel;
}
- (UILabel *)giftCountLabel {
if (!_giftCountLabel) {
_giftCountLabel = [UILabel labelInitWithText:@"X 1" font:kFontSemibold(36) textColor:UIColorFromRGB(0xFFE07B)];

View File

@@ -191,14 +191,29 @@
}
- (void)handleTap {
dispatch_async(dispatch_get_main_queue(), ^{
static BOOL isHandlingTap = NO;
if (isHandlingTap) {
NSLog(@"点击间隔过短,忽略此次点击");
return;
}
isHandlingTap = YES;
//
NSLog(@"有效点击处理");
@kWeakify(self);
//
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@kStrongify(self);
// 1521 3
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
});
[[GiftComboManager sharedManager] sendGift];
[self.playImageView startAnimation];
[self.countdownRingView resetCountdown];
[[GiftComboManager sharedManager] sendGift];
[self.playImageView startAnimation];
[self.countdownRingView resetCountdown];
isHandlingTap = NO;
});
}
- (void)handleTapSpace {

View File

@@ -84,4 +84,23 @@
return point;
}
- (CGPoint)animationPointAtStageViewByIndex:(NSInteger)index {
CGPoint point = CGPointZero;
if (index >= 0 && index <= 4) {
point = CGPointMake(paddingH + (mcWidth + marginH) * (index) + mcWidth / 2, firstRowTopMargin + mcHeight / 2);
}
if (index >= 5 && index < 10) {
point = CGPointMake(paddingH + (mcWidth + marginH) * (index - 5) + mcWidth / 2, sRowTop + mcHeight / 2);
}
if (index >= 10 && index < 15) {
point = CGPointMake(paddingH + (mcWidth + marginH) * (index - 10) + mcWidth / 2, tRowTop + mcHeight / 2);
}
point = [self convertPoint:point toView:nil];
return point;
}
@end

View File

@@ -2471,6 +2471,10 @@ XPCandyTreeInsufficientBalanceViewDelegate>
return [self.stageView animationPointAtStageViewByUid:uid];
}
- (CGPoint)animationPointAtStageViewByIndex:(NSInteger)index {
return [self.stageView animationPointAtStageViewByIndex:index];
}
- (void)getRoomBoomInfoSuccess:(NSArray <BoomDetailModel*> *)models {
[[RoomBoomManager sharedManager] updateBoomDetailArray:models];
[self.activityContainerView updateForBoomDetailArray:models];

View File

@@ -346,7 +346,7 @@ NSString * const kJSOpenPaymentCallback = @"openPaymentCallback";
didReceiveScriptMessage:(WKScriptMessage *)message {
[self.webview evaluateJavaScript:@"document.location.href"
completionHandler:^(id _Nullable response, NSError * _Nullable error) {
// NSLog(@"%@", response);
// NSLog(@"-- -- - -- - - -- -- - -- - -%@", response);
// NSLog(@"-- -- - -- - -%@: %@", message.name, message.body);
NSString *currentUrl = [NSString stringWithFormat:@"%@", response];
///host,便h5