iPhoneアプリケーションに1つのビューがあります。そのビューで、2 つの UIImageView を追加しました。たとえば、img_view1、img_view2 です。今、私は次のようにそのビューにタッチイベントを置きます。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Some code are here
}
タッチし始めた画像ビューを取得するにはどうすればよいですか?
iPhoneアプリケーションに1つのビューがあります。そのビューで、2 つの UIImageView を追加しました。たとえば、img_view1、img_view2 です。今、私は次のようにそのビューにタッチイベントを置きます。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Some code are here
}
タッチし始めた画像ビューを取得するにはどうすればよいですか?
UITouch *touch = [touches anyObject];
CGPoint pt = [touch locationInView:self];
if (CGRectContainsPoint(img_view1.frame, pt)
{
NSLog(@"Image View 1 touched");
}
等
画像ビューのユーザー インタラクションを xib で (またはプログラムで追加する場合はコードを介して) 有効にし、UIResponder メソッドの touchesBegan、touchesMoved、touchesEnded などを使用して、画像ビューのタッチを検出します。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch view] == yourImageView)
{
//add your code for image touch here
}
}
このコードを使用
UITouch *touch = [touches anyObject];
if (touch.view==imageView1) {
// do something
}
else if (touch.view==imageView2) {
// do something else
}
これがあなたが探しているものであることを願っています。
コーディングをお楽しみください :)
このコードを使用してください:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if(touch.view == img_view1)
{
}
else if(touch.view == img_view2)
{
}
}