新增 Banner 手势优化实施总结文档,记录了在 RoomAnimationView 中对 banner 手势系统的优化过程,包括手势识别器的重新设计、区域划分逻辑、tap 手势处理逻辑及交互区域检查等。同时,优化了多个视图中的通知处理逻辑,确保手势事件的准确传递与处理,提升用户交互体验。

This commit is contained in:
edwinQQQ
2025-08-15 19:34:25 +08:00
parent 84e146277a
commit 3f97b0293e
11 changed files with 871 additions and 910 deletions

View File

@@ -47,17 +47,17 @@
bannerView.gameID = model.skipContent;
[superView addSubview:bannerView];
[bannerView addNotification];
@kWeakify(bannerView);
[bannerView popEnterAnimation:^(BOOL finished) {
@kStrongify(bannerView);
[bannerView addNotification];
if (finished && bannerView.alreadyCancel == NO) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@kStrongify(bannerView);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[bannerView popLeaveAnimation:^(bool finished) {
if (bannerView.completeDisplay) {
bannerView.completeDisplay();
}
[bannerView removeNotification];
[bannerView removeFromSuperview];
}];
});
@@ -65,15 +65,49 @@
}];
}
- (void)handleSwipeNotification {
[self dismissBanner];
}
- (void)handleTapNotification:(NSNotification *)note {
NSValue *value = note.userInfo[@"point"];
CGPoint point = [value CGPointValue];
NSLog(@"🔄 GameUniversalBannerView: 接收到点击点 %@ (bannerContainer坐标系)", NSStringFromCGPoint(point));
// bannerContainer GameUniversalBannerView
CGPoint bannerPoint = [self convertPoint:point fromView:self.superview];
NSLog(@"🔄 GameUniversalBannerView: 转换为 banner 坐标系 %@", NSStringFromCGPoint(bannerPoint));
NSLog(@"%@", CGRectContainsPoint(self.goButton.frame, bannerPoint) ? @"YES" : @"NO");
// go
CGPoint goButtonPoint = [self.goButton convertPoint:bannerPoint fromView:self];
if ([self.goButton pointInside:goButtonPoint withEvent:nil]) {
NSLog(@"🎯 GameUniversalBannerView: tap 点与 go 按钮重合,触发游戏跳转事件");
[self handleTapGo];
} else {
CGPoint screenPoint = [self convertPoint:point toView:nil];
// FunctionContainer
[[NSNotificationCenter defaultCenter] postNotificationName:@"BannerTapToFunctionContainer"
object:nil
userInfo:@{@"point": [NSValue valueWithCGPoint:screenPoint]}];
}
}
- (void)addNotification {
@kWeakify(self);
[[NSNotificationCenter defaultCenter] addObserverForName:@"SwipeOutBanner"
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification * _Nonnull notification) {
@kStrongify(self);
[self dismissBanner];
}];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleSwipeNotification)
name:@"SwipeOutBanner"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleTapNotification:)
name:@"TapBanner"
object:nil];
}
- (void)removeNotification {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)dismissBanner {
@@ -358,16 +392,16 @@
}
// 穿
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (!self.userInteractionEnabled || self.hidden || self.alpha <= 0.01) {
return nil;
}
CGPoint goButtonPoint = [self.goButton convertPoint:point fromView:self];
if ([self.goButton pointInside:goButtonPoint withEvent:event]) {
return self.goButton;
}
// self
return self;
}
//- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
// if (!self.userInteractionEnabled || self.hidden || self.alpha <= 0.01) {
// return nil;
// }
// CGPoint goButtonPoint = [self.goButton convertPoint:point fromView:self];
// if ([self.goButton pointInside:goButtonPoint withEvent:event]) {
// return self.goButton;
// }
// // self
// return self;
//}
@end