Ios 如何在移动触摸的情况下获取多个imag视图的标记?
我需要从移动的触摸中获取imageView标记。我有10个imageView,标记从1到10。我需要在将手指移动到图像上时获取imageView标记 我可以通过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] ;
-(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。只有在视图不重叠的情况下,此操作才有效。当它们重叠时,它将返回最顶部的视图。