Hello, I created a subclass (called MyPicture) of the UIImageView with this methodes:
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.userInteractionEnabled = YES;
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"-- I AM TOUCHED --");
}
//…
When I create a UIImageView with the InterfaceBuilder with the class MyPicture everything works and the console writes: "I AM TOUCHED". But only, when I activate User Interaction Enabled in IB.
But when I create the UIImageView programmatly, it doenst work. in the ViewController.h:
MyButton * foo;
In the ViewController.m:
- (void)viewDidLoad {
flo = [[UIImageView alloc]initWithFrame:CGRectMake(0.0, 45.0, 324, 52.0)];
foo.userInteractionEnabled = YES;
foo.image = [UIImage imageNamed:@"Picture 1.png"];
[self.view addSubview:foo];
[super viewDidLoad];
}
I can see the picture, so it has to be my UIImageView subclass. But why doesn't he detect the touches?