1

我有一个 UIView 坐在 UIScrollView 上。

我希望能够在捕获 UIView 的同时正常滚动我的 ScrollView:

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

唯一的问题是我似乎无法让两个子视图同时检测触摸。我可以将顶部的设置userInteractionEnabled为 NO。但这并不能真正帮助我同时获得它们。

有什么想法吗??

谢谢!

4

1 回答 1

-1

在我的一个项目中,我在一个视图中捕捉到触摸,并以这种方式将方法传递给第二个:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];

    // Do something here

    [otherView touchesEnded:touches withEvent:event];
} 

编辑:您还可以使用第三个 UIView 来管理触摸。

在您的视图顶部放置第三个 UIView(它应该与您的屏幕一样宽)并让它管理您的触摸

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];

    // Get touch position
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:self.view];

    // Use location to pass touches to one view ot the other

    if (location == something) {
        [oneView touchesEnded:touches withEvent:event];
    } else {
        [otherView touchesEnded:touches withEvent:event];
    }
}
于 2013-08-17T23:03:48.123 回答