Working in a ViewController that has a few views which were added to it as subviews and I have a touchesBegan method:
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];
}
}
}
My question is how in that method can I discern which view was clicked? I've been doing it with those screen coordinates, but that won't work if I also move those views at runtime.
Is there a way to see which view was clicked in the touches or event or in this code from above:
UITouch *touch = [touches anyObject];
Any help appreciated // :)