简体   繁体   English

从TouchesMoved获取子视图参考

[英]Getting a subview Reference from TouchesMoved

I have a 2d-Grid of subviews. 我有一个2d网格的子视图。 As I drag my finger along these subviews I want to call discrete method's per view such that for each view I hover above this method is called once. 当我沿着这些子视图拖动手指时,我想为每个视图调用离散方法,这样,对于我悬停在此方法上方的每个视图,都将被调用一次。 Logging out the results of the touches parameter it seems that only one view is referenced through the drag, namely the one that touchesbegan was on top of. 注销touches参数的结果,似乎仅通过拖动引用了一个视图,即touchesbegan位于其上方的视图。 How do I get the view for where my finger is currently dragging based on coordinates? 如何获得基于坐标的手指当前拖动位置的视图?

- (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))
        {

        }
    }
}

Ref: iOS - Detecting touches in a UIView? 参考: iOS-在UIView中检测触摸?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM