How can I add an event recognizer to an object?
I have the following code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touches happened");
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.mainView];
for (UIView *view in self.mainView.subviews)
{
if ([view isKindOfClass:[ViewController class]] &&
CGRectContainsPoint(view.frame, touchLocation))
{
NSLog(@"my Touch Happened");
UIImageView *tmp = (UIImageView *)view;
if (selectedItem != tmp)
[self setSelected:tmp];
}
}
}
My goal is, if my image is touched, not tapped or long pressed but touched at all, to do the logic starting at the NSLog(@"found whats being touched");
I;ve use UIGestureRecognizers before and you add them to whatever you want.
[self.SomeImage addGestureRecognizer:rotate];
But how do I tell my objects to listen to this code?
I wanna know if the touched area is the same area that another object exists in? that is, if the user is trying to pan an item. I can handle the pan. But the second before the pan is the touch. How Do I go about finding that touch and the object that is associated with that!
UIViewController and UIView directly supports - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
You can directly put your function inside such objects. (i.e UIView or UIViewController)