2013-01-05 51 views
7

我有一个透明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中,水龙头也很完美。滚动,但不是很多。滚动视图滚动大约三个点,然后停止(因为我继续水平平移。)如果我放开速度,滚动视图然后拾取该速度并结束滚动。

什么可能导致滚动视图停止滚动,然后拿起速度的问题?

回答

2

从你发布的代码中,我假设你没有对透明UIView做任何事情。那你为什么不设置userInteractionEnabled = NO; ??

+0

假设透明视图需要响应至少一种类型的触摸,例如滑动或其他。 –

+0

嗯......我不知道为什么你的滚动停止和提取速度..但我会做的是..让我的UIScrollView处理所有事件..包括滑动,透明UIView应该处理...并创建一个回调函数,将该事件传递给该UIView ...还禁用UIView上的userInteractionEnabled ..所以UIScrollView以它应该的方式工作。nd UIView将处理它应该处理的唯一事件,因为UIScrollView会抓住它并传递它的UIView ...也许为时已晚,你回去改变它..但抱歉,我不知道如何解决你的问题。 – chuthan20

0

这里有一个更简单的解决方案,为我工作得好:

在透明的UIView(姑且称之为OverlayView的)使宽度和高度都为0(这样的观点不再技术上的UIScrollView的顶部)并设置clipsToBounds = NO(以便OverlayView的内容仍显示在UIScrollView的顶部)。

self.OverlayView.clipsToBounds = NO; 
CGRect frame = self.OverlayView.frame; 
self.OverlayView.frame = CGRectMake(frame.origin.x, frame.origin.y, 0, 0); 

请注意,如果OverlayView包含交互式控件(如上面的按钮),那么他们将不再工作。您需要将它移到UIScrollView上方自己的视图中。

0
#import "CustomUiView.h" 

@implementation CustomUiView.h 

-(BOOL) pointInside:(CGPoint)point withEvent:(UIEvent *)event{ 
    return NO; 
} 
@end 

您不希望进行交互的视图。 创建自定义UIView类,并使用此自定义视图作为顶点视图,在pointInside方法中返回NO。然后,触摸将自动变为不足。在你的情况下你的透明UIView将是UIView的CustomUiView子类。

相关问题