优化 GiftComboManager 接口,移除废弃方法并统一配置流程,提升代码可维护性和可读性。同时,更新 XPRoomViewController 和 XPSendGiftView 中的状态检查逻辑,确保连击状态的准确性。新增 GiftComboManager 调用方更新总结文档,记录了接口变更和优化效果。

This commit is contained in:
edwinQQQ
2025-08-19 14:39:27 +08:00
parent 961edefe4a
commit c551146afd
7 changed files with 370 additions and 319 deletions

View File

@@ -347,11 +347,8 @@ XPCandyTreeInsufficientBalanceViewDelegate>
[self handleGiftComboCallBack];
//#if DEBUG
// //
// [self setupDebugButtons];
//#endif
}
//- (void)test {
// XPMineHallAnchorIncomeStatisViewController *vc = [[XPMineHallAnchorIncomeStatisViewController alloc] init];
// [self.navigationController pushViewController:vc animated:YES];
@@ -366,7 +363,7 @@ XPCandyTreeInsufficientBalanceViewDelegate>
self.menuContainerView.hidden = comboViewDisplay;
// UI
if (comboViewDisplay && ![[GiftComboManager sharedManager] isGiftCombing]) {
if (comboViewDisplay && ![[GiftComboManager sharedManager] isActive]) {
NSLog(@"⚠️ 检测到UI隐藏请求但连击未进行执行强制重置");
[self forceBoomStateReset];
}
@@ -517,7 +514,7 @@ XPCandyTreeInsufficientBalanceViewDelegate>
self.freeView.hidden = YES;
//
if ([[GiftComboManager sharedManager] isGiftCombing]) {
if ([[GiftComboManager sharedManager] isActive]) {
NSLog(@"📱 房间即将退出,检查连击状态");
[self forceBoomStateReset];
}
@@ -554,7 +551,7 @@ XPCandyTreeInsufficientBalanceViewDelegate>
//
- (void)applicationDidEnterBackground:(NSNotification *)notification {
if ([[GiftComboManager sharedManager] isGiftCombing]) {
if ([[GiftComboManager sharedManager] isActive]) {
NSLog(@"📱 应用进入后台,检查连击状态");
[self forceBoomStateReset];
}
@@ -564,180 +561,12 @@ XPCandyTreeInsufficientBalanceViewDelegate>
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
if ([[GiftComboManager sharedManager] isGiftCombing]) {
if ([[GiftComboManager sharedManager] isActive]) {
NSLog(@"⚠️ 收到内存警告,检查连击状态");
[self forceBoomStateReset];
}
}
#pragma mark -
#if DEBUG
//
- (void)simulateStateInconsistency {
NSLog(@"🔴 [调试] 模拟状态不一致异常");
// UI
dispatch_async(dispatch_get_main_queue(), ^{
self.sideMenu.hidden = YES;
self.menuContainerView.hidden = YES;
NSLog(@"🔴 已隐藏底部栏和侧栏");
//
BOOL isCombing = [[GiftComboManager sharedManager] isGiftCombing];
NSLog(@" 当前连击状态:%@", isCombing ? @"进行中" : @"未进行");
if (!isCombing) {
NSLog(@"🔴 检测到状态不一致UI已隐藏但连击未进行");
//
[self forceBoomStateReset];
}
});
}
//
- (void)simulateAppEnterBackground {
NSLog(@"🔴 [调试] 模拟应用进入后台异常");
//
[[GiftComboManager sharedManager] enableToCombo:YES];
[[GiftComboManager sharedManager] resetCombo];
NSLog(@"🔴 已启动连击状态");
// 1
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"🔴 模拟应用进入后台...");
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidEnterBackgroundNotification
object:nil];
});
}
//
- (void)simulateMemoryWarning {
NSLog(@"🔴 [调试] 模拟内存警告异常");
//
[[GiftComboManager sharedManager] enableToCombo:YES];
[[GiftComboManager sharedManager] resetCombo];
NSLog(@"🔴 已启动连击状态");
// 1
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"🔴 模拟内存警告...");
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
});
}
// UI
- (void)simulateGiftViewUIDisappear {
NSLog(@"🔴 [调试] 模拟礼物面板UI消失");
//
[[NSNotificationCenter defaultCenter] postNotificationName:@"DebugSimulateComboViewDisappear"
object:nil];
}
//
- (void)simulateNetworkError {
NSLog(@"🔴 [调试] 模拟网络异常");
//
[[GiftComboManager sharedManager] enableToCombo:YES];
[[GiftComboManager sharedManager] resetCombo];
NSLog(@"🔴 已启动连击状态");
// 1
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"🔴 模拟网络异常,强制移除连击状态...");
[[GiftComboManager sharedManager] forceRemove];
});
}
//
- (void)startComboForTest {
NSLog(@"🟢 [调试] 启动连击用于测试");
[[GiftComboManager sharedManager] enableToCombo:YES];
[[GiftComboManager sharedManager] resetCombo];
NSLog(@"✅ 连击状态已启动,可以进行异常测试");
}
//
- (void)checkCurrentState {
BOOL isCombing = [[GiftComboManager sharedManager] isGiftCombing];
BOOL sideMenuHidden = self.sideMenu.hidden;
BOOL menuContainerHidden = self.menuContainerView.hidden;
NSLog(@"📊 [状态检查]");
NSLog(@" 连击状态:%@", isCombing ? @"进行中" : @"未进行");
NSLog(@" 侧栏状态:%@", sideMenuHidden ? @"隐藏" : @"显示");
NSLog(@" 底部栏状态:%@", menuContainerHidden ? @"隐藏" : @"显示");
if ((sideMenuHidden || menuContainerHidden) && !isCombing) {
NSLog(@"⚠️ 检测到状态不一致!");
} else {
NSLog(@"✅ 状态正常");
}
}
//
- (void)setupDebugButtons {
//
UIView *debugContainer = [[UIView alloc] initWithFrame:CGRectMake(20, 80, 280, 260)];
debugContainer.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
debugContainer.layer.cornerRadius = 12;
debugContainer.layer.borderWidth = 2;
debugContainer.layer.borderColor = [UIColor orangeColor].CGColor;
[self.view addSubview:debugContainer];
//
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, 280, 25)];
titleLabel.text = @"🔧 连击状态调试工具";
titleLabel.textColor = [UIColor orangeColor];
titleLabel.font = [UIFont boldSystemFontOfSize:16];
titleLabel.textAlignment = NSTextAlignmentCenter;
[debugContainer addSubview:titleLabel];
//
void (^createButton)(NSString *, CGRect, SEL) = ^(NSString *title, CGRect frame, SEL action) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button setTitle:title forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
button.backgroundColor = [[UIColor systemBlueColor] colorWithAlphaComponent:0.7];
button.layer.cornerRadius = 6;
button.frame = frame;
button.titleLabel.font = [UIFont systemFontOfSize:12];
[button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
[debugContainer addSubview:button];
};
//
createButton(@"启动连击", CGRectMake(10, 35, 80, 30), @selector(startComboForTest));
createButton(@"检查状态", CGRectMake(100, 35, 80, 30), @selector(checkCurrentState));
createButton(@"强制重置", CGRectMake(190, 35, 80, 30), @selector(forceBoomStateReset));
//
createButton(@"状态不一致", CGRectMake(10, 75, 80, 30), @selector(simulateStateInconsistency));
createButton(@"UI消失", CGRectMake(100, 75, 80, 30), @selector(simulateGiftViewUIDisappear));
createButton(@"进入后台", CGRectMake(190, 75, 80, 30), @selector(simulateAppEnterBackground));
//
createButton(@"内存警告", CGRectMake(10, 115, 80, 30), @selector(simulateMemoryWarning));
createButton(@"网络异常", CGRectMake(100, 115, 80, 30), @selector(simulateNetworkError));
//
UILabel *instructionLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 160, 260, 90)];
instructionLabel.text = @"使用步骤:\n1. 点击\"\"开始测试\n2. 点击各种异常模拟按钮\n3. 观察控制台日志输出\n4. 检查UI状态是否正确恢复\n5. 点击\"\"验证结果";
instructionLabel.textColor = [UIColor lightGrayColor];
instructionLabel.font = [UIFont systemFontOfSize:11];
instructionLabel.numberOfLines = 0;
instructionLabel.textAlignment = NSTextAlignmentLeft;
[debugContainer addSubview:instructionLabel];
}
#endif
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = [UIColor darkGrayColor];