iPhone:点击透明UIScrollView后面的视图 [英] iPhone: Click view behind transparent UIScrollView
问题描述
我有一个UIScrollView设置为具有清晰的背景。 scrollview的一部分确实有内容,但部分没有(因此它显示了其背后的其他视图)。我希望能够点击UIScrollView和后面的MKMapView,但仅限于UIScrollView的透明部分。
I have a UIScrollView that is set to have a clear background. Part of the scrollview does have content, but part does not (so it shows other views behind it). I would like to be able to click through the UIScrollView and to the MKMapView behind, but only for the transparent portion of the UIScrollView.
我找到了一些代码,我是很难理解如何工作:
I have found some code which I am having a real hard time understanding how to get working:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (![self yourMethodThatDeterminesInterestingTouches:touches withEvent:event])
[self.nextResponder touchesBegan:touches withEvent:event];
}
有人可以帮助我解决如何前进的问题事件到另一个视图后面的视图?我可以调用 - (void)touchesBegan:(NSSet *)触及来自UIViewController的事件:(UIEvent *)事件吗?
推荐答案
我们所做的是将UIScrollView子类化并实现将责任传递给其下的视图的逻辑,如果触摸发生在透明区域内。
What we did was to subclass UIScrollView and implement logic that passes responsibility down to views under it, if the touch happens inside of the transparent area.
在我们的例子中,透明区域由Y轴上的contentOffset 120定义,这意味着我们的内容在UIScrollView开头下方120点开始,代码看起来像这样:
In our case the transparent area is defined by contentOffset of 120 on Y axis, meaning our content starts 120 points below the start of the UIScrollView, and the code looks like this:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
if (self.contentOffset.y < 0 && point.y < 0.0) {
return NO;
} else {
return YES;
}
}
显然这个回应已经过了巅峰期但是希望这个对于任何寻找解决方案的人都很有帮助。
Obviously this response is well past its prime but hopefully this is helpful to anyone searching for a solution.
这篇关于iPhone:点击透明UIScrollView后面的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!