优化 GiftComboManager 接口,移除废弃方法并统一配置流程,提升代码可维护性和可读性。同时,更新 XPRoomViewController 和 XPSendGiftView 中的状态检查逻辑,确保连击状态的准确性。新增 GiftComboManager 调用方更新总结文档,记录了接口变更和优化效果。
This commit is contained in:
@@ -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];
|
||||
|
Reference in New Issue
Block a user