我需要从移动的触摸中获取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
}
}
}
但我不想使用
for
循环。还有其他替代方法可以获取imageView低于我的举动吗?任何帮助将不胜感激。谢谢。
最佳答案
用这个:
UIView* touchedView = [self.view hitTest:location withEvent:nil];
有了这个位置,您将获得一个touchedView,在您的情况下就是UIImageView。