いろいろ方法はあるようですが、今回つかった方法をメモしておきます。
viewController.xib
対象となる ImageView の User Interaction Enabled にチェックを入れる。
viewController.xib と viewController.m のあいだ
対象となるImageView を viewController.xib から controlを押しながら viewController.m に持ってくる
今回はimageViewと名付けてみました。
@property (nonatomic, weak) IBOutlet UIImageView *imageView;
viewController.m
タッチの開始、移動、終了、キャンセルをそれぞれ実装します。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if([event touchesForView:_imageView] != NULL) { NSLog(@"さわりはじめたなう。"); } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if([event touchesForView:_imageView] != NULL) { NSLog(@"指移動なう。"); } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if([event touchesForView:_imageView] != NULL) { NSLog(@"さわり終わったなう。"); } } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { if([event touchesForView:_imageView] != NULL) { NSLog(@"タッチキャンセルなう。"); } }
今回は以上です。