I created a custom subclass of UIView because I needed to override the drawRect method. I am trying to add a UITapGestureRecognizer to it, but this does not work for me. Here is the code of my ViewController:
MyCustomView *customView = [[MyCustomView alloc] initWithFrame:CGRectFrame(0, 30, 30, 30)]; [customView setUserInteractionEnabled:YES]; UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSomething)]; [customView addGestureRecognizer:tapGestureRecognizer];
I donβt understand why, when I touch the object of the UIView subclass, the gesture recognizer does not start.
Many thanks!
FIXED EXIT!
My view was on UIImageView, and that UIImageView did not set userInteractionEnabled
to YES.
source share