我有一个设置为具有清晰背景的 UIScrollView。部分 ScrollView 确实有内容,但部分没有(因此它显示了它后面的其他 View )。我希望能够通过 UIScrollView 单击并到达后面的 MKMapView,但仅限于 UIScrollView 的透明部分。
我发现了一些我很难理解如何开始工作的代码:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (![self yourMethodThatDeterminesInterestingTouches:touches withEvent:event])
[self.nextResponder touchesBegan:touches withEvent:event];
}
有人可以帮我想想如何将触摸事件转发到另一个 View 后面的 View 吗?我可以从 UIViewController 调用 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 吗?
最佳答案
我们所做的是将 UIScrollView 子类化并实现逻辑,如果触摸发生在透明 区域内,则将责任传递给它下面的 View 。
在我们的例子中,透明区域由 Y 轴上 120 的 contentOffset 定义,这意味着我们的内容开始于 UIScrollView 起点下方 120 点,代码如下所示:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
if (self.contentOffset.y < 0 && point.y < 0.0) {
return NO;
} else {
return YES;
}
}
显然,此响应已经过了巅峰期,但希望这对寻求解决方案的任何人都有帮助。
关于iPhone:单击透明 UIScrollView 后面的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4941570/