新增 Banner 手势优化实施总结文档,记录了在 RoomAnimationView 中对 banner 手势系统的优化过程,包括手势识别器的重新设计、区域划分逻辑、tap 手势处理逻辑及交互区域检查等。同时,优化了多个视图中的通知处理逻辑,确保手势事件的准确传递与处理,提升用户交互体验。
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user