Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在移动触摸的情况下获取多个imag视图的标记?_Ios_Objective C_Iphone - Fatal编程技术网

Ios 如何在移动触摸的情况下获取多个imag视图的标记?

Ios 如何在移动触摸的情况下获取多个imag视图的标记?,ios,objective-c,iphone,Ios,Objective C,Iphone,我需要从移动的触摸中获取imageView标记。我有10个imageView,标记从1到10。我需要在将手指移动到图像上时获取imageView标记 我可以通过 -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint location = [[touches anyObject] locationInView:self.view] ;

我需要从移动的触摸中获取imageView标记。我有10个imageView,标记从1到10。我需要在将手指移动到图像上时获取imageView标记

我可以通过

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

                    CGPoint location = [[touches anyObject] locationInView:self.view] ;
                    CGRect fingerRect = CGRectMake(location.x, location.y, 1, 1);


                    for(UIImageView *view in self.view.subviews)
                    {
                        CGRect subviewFrame = view.frame;

                        if(CGRectIntersectsRect(fingerRect, subviewFrame))
                         {
                            //we found the finally touched view
                         }
                    }
}
但是我不想对循环使用
。有没有其他替代品可以获取我移动下方的imageView?如有任何帮助,将不胜感激

谢谢。

用这个:

UIView* touchedView = [self.view hitTest:location withEvent:nil];

使用此位置,您将获得一个touchedView,在您的例子中是UIImageView。

只有在视图不重叠的情况下,此操作才有效。当它们重叠时,它将返回最顶部的视图。