触摸未检测到 - 子视图

时间:2016-06-09 05:34:20

标签: objective-c xcode uigesturerecognizer

我一直在努力解决这个问题。我正在使用带有scrollview的自动布局。在scrollview中是一个UIView,另一个是UIView,然后是其中的子视图。我无法触摸使用子视图。我尝试过touchesbegan和uitapgesture没有成功。有什么建议?这是布局层次结构。

ScrollView
---- UIView
     ------- UIView
             ------ UIView - Need to detect touch here.

编辑:

对不起,伙计们,正在工作。这是一些代码。我已经将我的scrollview子类化为接收触摸,因为它似乎最好地工作到目前为止其他视图子视图的子视图级别。

以下代码检测到视图是没有pointInside的类。我目前在收到视图的正确位置时遇到问题。

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UIView *relatedVidsView = [[[touches allObjects] firstObject] view];

for (int i = 0; i < relatedVidsView.subviews.count; i++) {
    UIView *view = [relatedVidsView.subviews objectAtIndex:i];
    CGPoint touchPoint = [[[touches allObjects] firstObject] locationInView:self];

    if ([view isKindOfClass:[RecipeVideoView class]] && [view pointInside:touchPoint withEvent:nil]) {
        NSLog(@"TEST");
    }
}

[super touchesBegan:touches withEvent:event]; }

编辑2:

所以我能够弄清楚这一点。我将包含我需要触摸事件的子视图的视图子类化。我所做的是使用touchesBegan将事件从父级传递到子视图。我稍后会发布我的代码,谢谢你的帮助。

0 个答案:

没有答案