サブビューとして追加されたいくつかのビューがある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];
助けていただければ幸いです//:)