gpt4 book ai didi

iphone - 当 View 移出其 super View 时,touchesBegan 停止工作

转载 作者:行者123 更新时间:2023-12-03 18:54:42 26 4
gpt4 key购买 nike

我正在使用 [aSubview TouchsBegan] 来移动 aSubview 在屏幕上相对于其 super View 的位置。它的 super View 并不比 subview 本身大很多。这非常简单,如以下代码片段所示:

    UITouch* touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:[self superview]];
self.center = touchPoint;

但是,一旦 aSubview 被移动,只要它的任何部分超出其父 View 的边界,该部分中的触摸就不再注册。换句话说,touchesBegan 不再触发。我希望 aSubview 中的触摸能够注册,无论它相对于其 super View 移动到哪里。

有什么想法吗?
霍华德

最佳答案

mcpunky 的答案几乎很好,除了您可以使pointInside函数始终返回YES。这样 View 将拦截所有触摸。

相反,我们需要进行更精细的检查:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{

return CGRectContainsPoint(self.subviewOutsideMe.frame, point) || CGRectContainsPoint(self.bounds, point);

}

关于iphone - 当 View 移出其 super View 时,touchesBegan 停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4422932/

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