我有一个透明UIView下的UIScrollView。我需要将所有平底锅和水龙头转移到滚动视图(仅水平滚动)。常规UIView使用UIPanGestureRecognizer的子类来跟踪垂直平底锅(Subclass found here)。在覆盖视图中,我重写触摸事件方法以将它们传递给UIScrollView。将触摸信息传递给另一个UIView下的UIScrollView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
[self.scrollView.panGestureRecognizer touchesBegan:touches withEvent:event];
[self.scrollView.singleTapGesture touchesBegan:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesCancelled:touches withEvent:event];
[self.scrollView.panGestureRecognizer touchesCancelled:touches withEvent:event];
[self.scrollView.singleTapGesture touchesCancelled:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];
[self.scrollView.panGestureRecognizer touchesEnded:touches withEvent:event];
[self.scrollView.singleTapGesture touchesEnded:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
[self.scrollView.panGestureRecognizer touchesMoved:touches withEvent:event];
[self.scrollView.singleTapGesture touchesMoved:touches withEvent:event];
}
覆盖视图,垂直锅完美的作品。在UIScrollView中,水龙头也很完美。滚动,但不是很多。滚动视图滚动大约三个点,然后停止(因为我继续水平平移。)如果我放开速度,滚动视图然后拾取该速度并结束滚动。
什么可能导致滚动视图停止滚动,然后拿起速度的问题?
假设透明视图需要响应至少一种类型的触摸,例如滑动或其他。 –
嗯......我不知道为什么你的滚动停止和提取速度..但我会做的是..让我的UIScrollView处理所有事件..包括滑动,透明UIView应该处理...并创建一个回调函数,将该事件传递给该UIView ...还禁用UIView上的userInteractionEnabled ..所以UIScrollView以它应该的方式工作。nd UIView将处理它应该处理的唯一事件,因为UIScrollView会抓住它并传递它的UIView ...也许为时已晚,你回去改变它..但抱歉,我不知道如何解决你的问题。 – chuthan20