soleil
soleil

Reputation: 13085

UIViewController is not receiving touchesBegan message

I have a UIScrollView in my UIViewController. I need to detect ANY kind of touch on it, and then do something. What else do I need?

- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self becomeFirstResponder];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"TOUCHED"); // never happens
    for (UITouch *touch in touches) {
        if ( [touch view] == self.myScrollView)
        {
            //do something
        }
    } 
}

Upvotes: 2

Views: 11420

Answers (2)

Sujay
Sujay

Reputation: 2520

use a controller to set the UserInteractionEnabled property to true on a UIView class.

try imgTouchMe.UserInteractionEnabled = true;

or follow

enter image description here

Upvotes: -1

jimpic
jimpic

Reputation: 5520

Two choices:

  1. Subclass UIScrollView and implement your touchesBegan[...] code there
  2. Add a UIView to your UIScrollView and use the UIView's touchesBegan[...] delegate method

Upvotes: 3

Related Questions