新增 Banner 手势优化实施总结文档,记录了在 RoomAnimationView 中对 banner 手势系统的优化过程,包括手势识别器的重新设计、区域划分逻辑、tap 手势处理逻辑及交互区域检查等。同时,优化了多个视图中的通知处理逻辑,确保手势事件的准确传递与处理,提升用户交互体验。
This commit is contained in:
@@ -88,20 +88,21 @@
|
||||
break;
|
||||
}
|
||||
|
||||
[banner addNotification];
|
||||
|
||||
[superView addSubview:banner];
|
||||
|
||||
@kWeakify(banner);
|
||||
// 使用 POP 动画移动 banner 到目标位置
|
||||
[banner popEnterAnimation:^(BOOL finished) {
|
||||
@kStrongify(banner);
|
||||
[banner addNotification];
|
||||
if (finished) {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
@kStrongify(banner);
|
||||
[banner popLeaveAnimation:^(bool finished) {
|
||||
if (banner.animationComplete) {
|
||||
banner.animationComplete();
|
||||
}
|
||||
[banner removeNotification];
|
||||
[banner removeFromSuperview];
|
||||
}];
|
||||
});
|
||||
@@ -113,15 +114,37 @@
|
||||
[self.svgaImageView stopAnimation];
|
||||
}
|
||||
|
||||
- (void)handleSwipeNotification {
|
||||
[self dismissBanner];
|
||||
}
|
||||
|
||||
- (void)handleTapNotification:(NSNotification *)note {
|
||||
NSValue *value = note.userInfo[@"point"];
|
||||
CGPoint point = [value CGPointValue];
|
||||
|
||||
// 将 banner 中的点转换为屏幕坐标系
|
||||
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 {
|
||||
@@ -406,16 +429,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