在一个 ViewController 中工作,它有几个视图作为子视图添加到其中,我有一个 touchesBegan 方法:
UIImageView *testImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"test.png"]];
testImage.frame = CGRectMake(0, 0, 480, 280);
[self.view addSubview:testImage];
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint point;
UITouch *touch = [touches anyObject];
point.x = [touch locationInView:self.view].x;
point.y = [touch locationInView:self.view].y;
if ( point.y >= 280 && point.y <= 320 )
{
if ( point.x >= 0 && point.x <= 160 )
{
[self menu1];
}
if ( point.x >= 161 && point.x <= 320 )
{
[self menu2];
}
if ( point.x >= 321 && point.x <= 480 )
{
[self menu3];
}
}
}
我的问题是如何在该方法中辨别点击了哪个视图?我一直在使用这些屏幕坐标进行操作,但是如果我在运行时也移动这些视图,那将无法正常工作。
有没有办法从上面查看在触摸或事件或此代码中单击了哪个视图:
UITouch *touch = [touches anyObject];
任何帮助表示赞赏// :)