2

iphoneアプリを開発し、UIImageviewを使用し、不規則な形状の画像を設定しました

// uiimageview type shutter
shutter = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,32.5)];

//setting image on shutter
UIImage* shutterimg = [UIImage imageNamed:@"trayshutter.png"];
[shutter setImage:shutterimg];
// User interaction
shutter.userInteractionEnabled=YES;

そして私はtouchesbeganを使用してタッチを取得します

すべて問題ありませんが、問題は、imageviewのCGRectMake(つまり、0,0,320,32.5)が占めるすべての長方形領域でイベントを取得するのに対し、画像(-----の形状)でのみイベントを必要とすることです。 ||||| -----)。

cgrectmakeでカバーされている残りの領域ではなく、画像でのみイベントを取得するようにするにはどうすればよいですか?

4

1 に答える 1

0
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
  UITouch *touch = [touches anyObject];
  if ([touch view] == yourDesiredImage) {
    // Do something here
  }
}

編集:多分あなたはUITapGestureRecognizer代わりに試すことができます:

UITapGestureRecognizer * tapGestureRecognizer = [[UITapGestureRecognizer alloc] init];
[tapGestureRecognizer addTarget:self action:@selector(yourTouchMethod:)];
[tapGestureRecognizer setNumberOfTapsRequired:1];
[shutter addGestureRecognizer:tapGestureRecognizer];
[tapGestureRecognizer release];
于 2012-01-14T08:08:28.343 に答える