You should try setting this property:
img.userInteractionEnabled = YES;
But this is not enough, because the methods:
– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
belong to the UIResponder class (the UIVIew base class), and not to the UIViewController.
So, if you want to be called, you must define a subclass of the UIView class (or UIImageView in your case), where you override the base methods.
Example:
MyImageView.h
@interface MyImageView : UIImageView {
}
@end
MyImageView.m
@implementation MyImageView
- (id)initWithFrame:(CGRect)aRect {
if (self = [super initWithFrame:rect]) {
self.userInteractionEnabled = YES;
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touchesBegan!");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touchesEnded!");
}
@end
MyImageView :
img = [[MyImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:img]
[img release]
( , self.view userInteractionEnabled, YES, ).