touchedBegan と touchedEnded をいじってみました。私は基本的に、自分のビューでイメージを作成しようとしています。次に、ユーザーが画像に触れたときに何かを実行できるようにします。画像に触れると、ifステートメント内のコードが実行されます。私が間違っていることについて何か考えはありますか?
viewDidload:
UIImage *image = [UIImage imageNamed:@"myimage1.png"];
imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0, 0, 320, 200);
[self.view addSubview:imageView];
imageViewsArray = [NSArray arrayWithObjects:imageView, nil];
touchesEnded:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
// do this on touch
UIView *touchedView = [touch view];
if ([imageViewsArray indexOfObject:touchedView] != NSNotFound) {
// not not found means found!
NSLog(@"Got Touch!");
}
}
私もこのif文を使ってみました:
if ([[touch view] isKindOfClass:[UIImageView class]]) {
NSLog(@"Got Touch 2!");
}