Files
peko-ios/YuMi/Modules/YMRoom/View/AnimationView/XPRoomAnimationHitView.m
2025-01-15 19:02:58 +08:00

44 lines
1.2 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// YMRoomAnimationBaseView.m
// YUMI
//
// Created by YUMI on 2021/11/22.
//
#import "XPRoomAnimationHitView.h"
// MARK: 只要有子视图命中,就交给子视图处理;子视图都没命中就放弃处理,自己不接收任何触摸事件。
@implementation XPRoomAnimationHitView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
// 应该先判断自身是否可以接收事件
if (!self.userInteractionEnabled || self.hidden || self.alpha <= 0.01) {
return nil;
}
// 可选判断点是否在自身bounds内
// if (!CGRectContainsPoint(self.bounds, point)) {
// return nil;
// }
// 从后往前遍历子视图
for (NSInteger i = self.subviews.count - 1; i >= 0; i--) {
UIView *subView = [self.subviews xpSafeObjectAtIndex:i];
if (!subView) continue;
CGPoint convertPoint = [subView convertPoint:point fromView:self];
UIView *hitTestView = [subView hitTest:convertPoint withEvent:event];
if (hitTestView) {
return hitTestView;
}
}
// 如果子视图都不响应,则不处理
return nil;
}
@end