Reputation: 1
In iOS7, gesture recognizers on programmatically added subviews do not seem to be triggering, however when programmatically adding gesture recognizers to views that were added via my storyboard interface, gesture recognizers trigger no problem. This used to work in iOS6 it has suddenly stopped working in iOS7. What am I doing wrong or what have I missed?
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSomethingWhenTapped:)];
UIImageView *imageToTap = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Transparent" ofType:@"png"]]];
imageToTap.frame = CGRectMake(0, 0, 100, 100);
imageToTap.backgroundColor = [UIColor redColor];
[imageToTap addGestureRecognizer:tapGestureRecognizer];
[self.view addSubview:imageToTap];
EDIT:
Although I forgot to add the userInteractionEnabled property to my example (it is set in my real code) the below suggestions to add it made me realize my real issue is an odd frame/bounds issue I'm seeing in Landscape mode.
Thanks for the help!
Upvotes: 0
Views: 1448
Reputation: 3360
UIImageView
has userInteractionEnabled
disabled by default. So you have to enable it manually.:
[imageToTap setUserInteractionEnabled:YES];
Upvotes: 1
Reputation: 1349
By default, user interaction is disabled on UIImageView.
Try setting imageToTap.userInteractionEnabled = YES
and see if that works for you.
Hope this helps
Upvotes: 0