[英]Passing touches through a UIView to a UIScrollView not working
我有一个从UIScrollView控制器派生的视图,我用它来浏览库中的图像。 这很好。
我在右侧覆盖了一个UIView来处理触摸,以便快速滚动图像列表。 我的问题是,如果我将触摸传递给'super'或'nextResponder',它们永远不会进入下面的UIScrollView对象。
我的问题是如何强制下面的UIScrollView来处理我不需要处理的触摸? 我正在设置一个0.3秒的计时器,在此期间所有触摸都传递给UIScrollView进行处理。 因此,如果用户启动了滑动手势来翻页,则会发生这种情况。
这是touchesBegan方法的代码:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
// Start a timer to trigger the display of the slider and the processing of events.
touchesTimer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(showSlider:) userInfo:nil repeats:NO];
// Where are we at right now?
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
lastPage = [self page:currentPoint.y];
// Pass the event though until we need it.
// [self.nextResponder touchesBegan:touches withEvent:event];
if ([touch.view isKindOfClass:[UIScrollView class]])
{
if (self.nextResponder != nil &&
[self.nextResponder respondsToSelector:@selector(touchesEnded:withEvent:)])
{
[self.nextResponder touchesEnded:touches withEvent:event];
}
}
}
我会尝试使用常规的UIViewController而不是UIScrollViewController,然后在需要的地方添加滚动视图对象,并在右侧放置您想要的滚动视图。 这种方式它们是分开的,触摸不会混淆。
这是一个更适合我的简单解决方案:
在UIScrollview顶部的UIView中,宽度和高度均为0(因此视图不再在技术上位于UIScrollView之上)并设置clipsToBounds = NO(以便视图的内容仍显示在顶部UIScrollView中)。
self.OverlayView.clipsToBounds = NO;
CGRect frame = self.OverlayView.frame;
self.OverlayView.frame = CGRectMake(frame.origin.x, frame.origin.y, 0, 0);
请注意,如果UIView包含交互式控件,则它们将不再起作用。 您需要将其移动到UIScrollView上方的自己的视图中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.