// GameBannerGestureManager.m #import "GameBannerGestureManager.h" @interface GameBannerGestureManager () @property (nonatomic, assign) BOOL isEnabled; @property (nonatomic, strong) UISwipeGestureRecognizer *swipeGesture; @end @implementation GameBannerGestureManager - (void)enableGestureForGameMode { if (self.isEnabled) return; [self cleanupAllGestures]; // 创建新的 swipe 手势 self.swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe)]; // 配置手势识别器,确保不拦截触摸事件 self.swipeGesture.delaysTouchesBegan = NO; self.swipeGesture.delaysTouchesEnded = NO; self.swipeGesture.cancelsTouchesInView = NO; self.swipeGesture.requiresExclusiveTouchType = NO; // 设置 swipe 方向 if (isMSRTL()) { self.swipeGesture.direction = UISwipeGestureRecognizerDirectionRight; } else { self.swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft; } [self.bannerContainer addGestureRecognizer:self.swipeGesture]; _isEnabled = YES; NSLog(@"🎮 GameBannerGestureManager: swipe 手势已启用"); } - (void)disableGestureForGameMode { if (!self.isEnabled) return; [self cleanupAllGestures]; _isEnabled = NO; NSLog(@"🎮 GameBannerGestureManager: swipe 手势已禁用"); } - (void)cleanupAllGestures { if (self.swipeGesture) { [self.bannerContainer removeGestureRecognizer:self.swipeGesture]; self.swipeGesture = nil; } // 清理可能存在的其他手势识别器 NSArray *gestures = [self.bannerContainer.gestureRecognizers copy]; for (UIGestureRecognizer *gesture in gestures) { if ([gesture isKindOfClass:[UISwipeGestureRecognizer class]]) { [self.bannerContainer removeGestureRecognizer:gesture]; } } } - (void)resetState { [self cleanupAllGestures]; _isEnabled = NO; } - (void)handleSwipe { NSLog(@"🎮 GameBannerGestureManager: 检测到 swipe 手势,发送 banner 移除通知"); // 检查当前是否有可见的 banner UIView *currentVisibleBanner = nil; for (UIView *subview in self.bannerContainer.subviews) { if (!subview.hidden && subview.alpha > 0.01) { currentVisibleBanner = subview; break; } } if (currentVisibleBanner) { NSLog(@"🎮 当前有可见 banner: %@,发送 SwipeOutBanner 通知", NSStringFromClass([currentVisibleBanner class])); [[NSNotificationCenter defaultCenter] postNotificationName:@"SwipeOutBanner" object:currentVisibleBanner]; } else { NSLog(@"🎮 当前没有可见 banner,忽略 swipe 手势"); } } @end