新增连击状态管理功能,包含强制重置连击状态的方法和应用生命周期保护;在 XPSendGiftView 和 GiftComboManager 中实现相关逻辑,确保 UI 状态与连击状态一致;注册通知以处理连击状态的强制重置,增强用户体验和系统稳定性。
This commit is contained in:
@@ -258,3 +258,5 @@ typedef void(^NIMSDKStatusChangeBlock)(NIMSDKLoginStatus status);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
|
||||
|
||||
|
@@ -404,3 +404,5 @@
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
|
@@ -28,6 +28,9 @@ typedef enum : NSUInteger {
|
||||
} ComboFlagActionType;
|
||||
|
||||
|
||||
// 通知常量定义
|
||||
UIKIT_EXTERN NSString * const kBoomStateForceResetNotification;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface GiftComboManager : NSObject
|
||||
@@ -58,6 +61,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (void)resetCombo;
|
||||
- (void)sendGift;
|
||||
- (void)forceRemove;
|
||||
- (void)forceBoomStateReset;
|
||||
- (BOOL)loadEnable;
|
||||
|
||||
// 第一个 combo 由 send gift view 发起,需要手动 combo + 1
|
||||
|
@@ -8,6 +8,8 @@
|
||||
|
||||
#import "GiftComboManager.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <Bugly/Bugly.h>
|
||||
|
||||
#import "Api+Gift.h"
|
||||
@@ -20,6 +22,9 @@
|
||||
|
||||
#import "GiftComboFlagView.h"
|
||||
|
||||
// 通知常量实现
|
||||
NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotification";
|
||||
|
||||
@interface GiftComboManager ()
|
||||
|
||||
@property (nonatomic, assign) BOOL enableCombo;
|
||||
@@ -126,13 +131,65 @@
|
||||
}
|
||||
|
||||
- (void)forceRemove {
|
||||
// 调用新的强制重置方法
|
||||
[self forceBoomStateReset];
|
||||
|
||||
// 通知UI移除连击面板
|
||||
if (self.actionCallback) {
|
||||
self.actionCallback(ComboAction_RemovePanel);
|
||||
}
|
||||
if (self.handleRoomUIChanged) {
|
||||
self.handleRoomUIChanged(NO);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)forceBoomStateReset {
|
||||
NSLog(@"🚨 执行强制Boom连击状态重置");
|
||||
|
||||
// 1. 立即停止所有定时器(无条件停止)
|
||||
[self forceStopAllTimers];
|
||||
|
||||
// 2. 清空所有队列
|
||||
[self clearAllQueues];
|
||||
|
||||
// 3. 重置所有状态标志
|
||||
self.isCombing = NO;
|
||||
self.enableCombo = NO;
|
||||
|
||||
// 4. 清理回调
|
||||
self.actionCallback = nil;
|
||||
|
||||
// 5. 发送通知(优先级最高,通知所有相关组件)
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kBoomStateForceResetNotification
|
||||
object:nil];
|
||||
});
|
||||
|
||||
// 6. 强制恢复UI(确保底部栏和侧栏显示)
|
||||
if (self.handleRoomUIChanged) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.handleRoomUIChanged(NO);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 无条件停止定时器
|
||||
- (void)forceStopAllTimers {
|
||||
if (self.timer) {
|
||||
dispatch_source_cancel(self.timer);
|
||||
self.timer = nil; // 立即置空,不等待回调
|
||||
}
|
||||
|
||||
if (self.comboFlagTimer) {
|
||||
dispatch_source_cancel(self.comboFlagTimer);
|
||||
self.comboFlagTimer = nil;
|
||||
}
|
||||
}
|
||||
|
||||
// 清空所有队列
|
||||
- (void)clearAllQueues {
|
||||
@synchronized (self) {
|
||||
[self.requestQueue removeAllObjects];
|
||||
[self.giftComboQueue removeAllObjects];
|
||||
[self.comboFlagQueue removeAllObjects];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSInteger)loadComboCountFromSendGiftView {
|
||||
|
@@ -36,6 +36,12 @@ typedef NS_ENUM(NSInteger, SendGiftType) {
|
||||
///选中的礼物id
|
||||
@property (nonatomic, copy) NSString *selectGiftId;
|
||||
|
||||
// 移除连击相关视图
|
||||
- (void)removeAllComboRelatedViews;
|
||||
|
||||
// 强制重置连击状态
|
||||
- (void)forceBoomStateReset;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -128,6 +128,62 @@ UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - 连击状态管理
|
||||
|
||||
// 移除连击相关视图
|
||||
- (void)removeAllComboRelatedViews {
|
||||
// 移除连击面板
|
||||
if (self.comboView && self.comboView.superview) {
|
||||
[self.comboView stopTimer];
|
||||
[self.comboView endCombo];
|
||||
[self.comboView removeFromSuperview];
|
||||
self.comboView = nil;
|
||||
}
|
||||
|
||||
// 恢复其他视图的显示状态
|
||||
self.contentView.hidden = NO;
|
||||
if (self->_constellationBanner) {
|
||||
self.constellationBanner.hidden = NO;
|
||||
}
|
||||
if (self->_luckyBroadcastView) {
|
||||
self.luckyBroadcastView.hidden = NO;
|
||||
}
|
||||
if (self->_bravoGiftView) {
|
||||
self.bravoGiftView.hidden = NO;
|
||||
}
|
||||
}
|
||||
|
||||
// 强制重置连击状态
|
||||
- (void)forceBoomStateReset {
|
||||
NSLog(@"🔧 XPSendGiftView 强制重置连击状态");
|
||||
|
||||
// 1. 移除连击相关视图
|
||||
[self removeAllComboRelatedViews];
|
||||
|
||||
// 2. 重置连击管理器状态
|
||||
[[GiftComboManager sharedManager] forceBoomStateReset];
|
||||
}
|
||||
|
||||
// 处理连击状态强制重置通知
|
||||
- (void)handleBoomStateForceReset:(NSNotification *)notification {
|
||||
NSLog(@"📢 XPSendGiftView 收到连击状态强制重置通知");
|
||||
|
||||
// 只处理视图相关的重置,不再调用 GiftComboManager 的重置
|
||||
// 因为通知是由 GiftComboManager 发出的,避免循环调用
|
||||
[self removeAllComboRelatedViews];
|
||||
}
|
||||
|
||||
// 视图控制器生命周期保护
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[super viewWillDisappear:animated];
|
||||
|
||||
// 如果连击正在进行,强制重置
|
||||
if ([[GiftComboManager sharedManager] isGiftCombing]) {
|
||||
NSLog(@"📱 礼物面板即将消失,检查连击状态");
|
||||
[self forceBoomStateReset];
|
||||
}
|
||||
}
|
||||
|
||||
- (instancetype)initWithType:(SendGiftType)type uid:(NSString * __nullable)uid{
|
||||
if (self = [super init]) {
|
||||
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
||||
@@ -140,6 +196,12 @@ UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification;
|
||||
- (void)viewDidLoad {
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getFreeGiftCountdownNotification:) name:kFreeGiftCountdownNotification object:nil];
|
||||
|
||||
// 注册连击状态强制重置通知
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(handleBoomStateForceReset:)
|
||||
name:kBoomStateForceResetNotification
|
||||
object:nil];
|
||||
|
||||
[self initSubViews];
|
||||
[self initSubViewConstraints];
|
||||
|
@@ -364,6 +364,12 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.sideMenu.hidden = comboViewDisplay;
|
||||
self.menuContainerView.hidden = comboViewDisplay;
|
||||
|
||||
// 添加状态验证:如果要隐藏UI,确保连击确实在进行
|
||||
if (comboViewDisplay && ![[GiftComboManager sharedManager] isGiftCombing]) {
|
||||
NSLog(@"⚠️ 检测到UI隐藏请求但连击未进行,执行强制重置");
|
||||
[self forceBoomStateReset];
|
||||
}
|
||||
});
|
||||
}];
|
||||
}
|
||||
@@ -415,6 +421,12 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
- (void)setupNotifications {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myGiftEffectUpdate:) name:kRoomGiftEffectUpdateNotificationKey object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openRedPacketNotification:) name:@"kOpenRedPacketNotification" object:nil];
|
||||
|
||||
// 添加应用生命周期保护
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationDidEnterBackground:)
|
||||
name:UIApplicationDidEnterBackgroundNotification
|
||||
object:nil];
|
||||
|
||||
@kWeakify(self);
|
||||
[[NSNotificationCenter defaultCenter] addObserverForName:@"kExchangeRoomAnimationViewAndGameViewIndex"
|
||||
@@ -497,6 +509,12 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
-(void)viewWillDisappear:(BOOL)animated{
|
||||
[super viewWillDisappear:animated];
|
||||
self.freeView.hidden = YES;
|
||||
|
||||
// 如果连击正在进行,强制重置
|
||||
if ([[GiftComboManager sharedManager] isGiftCombing]) {
|
||||
NSLog(@"📱 房间即将退出,检查连击状态");
|
||||
[self forceBoomStateReset];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewDidDisappear:(BOOL)animated{
|
||||
@@ -511,6 +529,41 @@ XPCandyTreeInsufficientBalanceViewDelegate>
|
||||
[XPSkillCardPlayerManager shareInstance].isInRoomVC = YES;
|
||||
}
|
||||
|
||||
#pragma mark - 连击状态管理
|
||||
|
||||
// 强制重置连击状态和恢复UI
|
||||
- (void)forceBoomStateReset {
|
||||
NSLog(@"🔧 XPRoomViewController 强制重置连击状态");
|
||||
|
||||
// 1. 直接重置连击管理器(会自动发送通知给所有相关组件)
|
||||
[[GiftComboManager sharedManager] forceBoomStateReset];
|
||||
|
||||
// 2. 确保UI恢复(双重保障)
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.sideMenu.hidden = NO;
|
||||
self.menuContainerView.hidden = NO;
|
||||
NSLog(@"🔄 强制恢复底部操作栏和侧栏显示");
|
||||
});
|
||||
}
|
||||
|
||||
// 应用生命周期保护
|
||||
- (void)applicationDidEnterBackground:(NSNotification *)notification {
|
||||
if ([[GiftComboManager sharedManager] isGiftCombing]) {
|
||||
NSLog(@"📱 应用进入后台,检查连击状态");
|
||||
[self forceBoomStateReset];
|
||||
}
|
||||
}
|
||||
|
||||
// 内存警告保护
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
|
||||
if ([[GiftComboManager sharedManager] isGiftCombing]) {
|
||||
NSLog(@"⚠️ 收到内存警告,检查连击状态");
|
||||
[self forceBoomStateReset];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Private Method
|
||||
- (void)initSubViews {
|
||||
self.view.backgroundColor = [UIColor darkGrayColor];
|
||||
|
@@ -420,3 +420,5 @@ if (![partitionId isEqualToString:self.userInfo.partitionId]) {
|
||||
**最后更新**: 2024年12月
|
||||
**维护人员**: 开发团队
|
||||
|
||||
|
||||
|
||||
|
@@ -616,3 +616,5 @@ A: 检查APNS证书配置,确保设备Token正确上传。
|
||||
**最后更新**: 2024年12月
|
||||
**维护人员**: 开发团队
|
||||
|
||||
|
||||
|
||||
|
@@ -553,3 +553,5 @@ A: 检查推送消息格式,确保解析逻辑正确。
|
||||
**最后更新**: 2024年12月
|
||||
**维护人员**: 开发团队
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user