gpt4 book ai didi

iOS 在其 subview 中接收父 View 的触摸事件

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:18:25 26 4
gpt4 key购买 nike

问题: 有没有办法在它的 subview 中直接接收来自 super View 的触摸(即在 subview 边界之外的触摸)?

我想避免委托(delegate)(正式/非正式)、NSNotification、代理或任何其他中间解决方案将触摸事件从一个 View 转发到另一个 View 。

最佳答案

这样就可以了。覆盖 subview 中的 pointInside。希望足够直接满足您的要求。

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
point = [self convertPoint:point toCoordinateSpace:self.superview];
CGRect frame = self.superview.frame;
if (CGRectContainsPoint(frame, point)) {
return YES;
}
return [super pointInside:point withEvent:event];
}

关于iOS 在其 subview 中接收父 View 的触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27923171/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com