【问题标题】:Getting a subview Reference from TouchesMoved从 TouchesMoved 获取子视图参考
【发布时间】:2015-11-14 04:44:02
【问题描述】:

我有一个二维网格的子视图。当我沿着这些子视图拖动手指时,我想调用离散方法的每个视图,这样对于我悬停在上面的每个视图,这个方法都会被调用一次。注销 touches 参数的结果,似乎只有一个视图通过拖动引用,即 touchesbegan 位于其顶部的视图。如何根据坐标获取手指当前拖动位置的视图?

【问题讨论】:

  • 1) 使用来自 parentView 的 hitTest。 2) 将触摸传递给 nextResponder()

标签: ios uiview touchesmoved


【解决方案1】:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self.contentView];

    for (UIView *view in self.contentView.subviews)
    {
        if ([view isKindOfClass:[MyView class]] &&
            CGRectContainsPoint(view.frame, touchLocation))
        {

        }
    }
}

参考:iOS - Detecting touches in a UIView?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-21
    • 2023-03-26
    相关资源
    最近更新 更多