2012-01-26 48 views
0

我在视图中添加了一个scrollview和imageview。当我触摸这个imageview时,我的scrollview会滚动。在我的滚动视图中,有很多图像浏览,其中有触摸事件分开编写。将触摸事件传递给滚动视图中的uiimageview作为子视图添加到视图中

这里是视图层次

      View 
          | 
          | 
        ------- -------- 
        |     | 
       imageView1   scrollview 
             | 
            ........................... 
            |   |  |.....| 
           imageviews2 

Imageview1高于在外观imagesview2。

而当我滚动scrollview时,它不可能触及scrollview中的一些imageViews,因为它在视图内的imageview背后。

如何将触摸事件传递到imageviews2,只要它在imageview1后面。

+0

'setUserInteractionEnabled:NO'为'imageView1'? – basvk

+0

我很抱歉,无法按照您的指示进行操作,因为用户触摸滚动视图时必须滚动。如果我这样做,那么无法添加该功能。 – iOSD

+0

如果你禁用imageView1上的userInteraction,滚动'UIScrollView'仍然会启用... – basvk

回答

0

你需要继承UIView,并在子类中覆盖

​​

跳过imageView1。

你可能逃脱子类UIImageView和实例imageView1作为类的成员,和压倒一切的pointInside

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

你可以用一个例子或其他什么来解释它吗? – iOSD

0

不也忘了取消“延迟内容触摸”和“撤销内容摩的”上你的滚动视图!

0

我希望这个答案可能对某人有用。我已经做到了,而不使用hittest。

在scrollview中检索了所有子视图,并检查它是否是图像视图并执行了以下操作。

使用[view touchesBegan:touches withEvent:event]将touchevents传递给另一个视图;我们必须在touchesMoved和touchesEnded中写同样的东西。

感谢,

Joku

0

你需要触摸事件传递给那些父视图的边界之外的UIViews。

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { 

    // Convert the point to the target view's coordinate system. 
    // The target view isn't necessarily the immediate subview 
    CGPoint pointForTargetView = [self.targetView convertPoint:point fromView:self]; 

    if (CGRectContainsPoint(self.targetView.bounds, pointForTargetView)) { 

     // The target view may have its view hierarchy, 
     // so call its hitTest method to return the right hit-test view 
     return [self.targetView hitTest:pointForTargetView withEvent:event]; 
    } 

    return [super hitTest:point withEvent:event]; 
} 

https://developer.apple.com/library/ios/qa/qa2013/qa1812.html

相关问题