I have problems detecting touch events on my UIImageView. I have sub classed UIImageView and overrided canBecomeFirstResponder, touchedBegan and touchesEnded:
@implementation ImageViewNext
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.userInteractionEnabled = YES;
}
return self;
}
-(BOOL)canBecomeFirstResponder
{
return YES;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Touches Began event");
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Touches Ended");
}
I have ensured that all the parent views have User Interaction Enabled.
But I don’t get my events?
I have tried to find the solution here but without any luck. But in my search I found that some people use “UIGestureRecognizer” to get the same effect. So as a side question, what is the “right” solution use the override method or use UIGestureRecognizer? I don’t like the solution where a normal button is given an image, so please keep those post away 🙂
Are you sure your
initWithFrame:is called? UIViews have two designated initializers,initWithFrame:andinitWithCoder, depending on how they are created.