PedroMeira
PedroMeira

Reputation: 97

Have problems in the touches

I have a UIView with a UIScrollView and I want to catch the event touches but I can not. Not goes into any method below. What is the problem?

- (void) touchesEnded: (NSSet *) toca withEvent: (UIEvent *) evento
{
     NSLog (@ "touchesEnded");

}
- (void) touchesBegan: (NSSet *) toca withEvent: (UIEvent *) evento
{

     NSLog (@ "touchesBegan");

}
- (Void) touchesMoved: (NSSet *) toca withEvent: (UIEvent *) evento
{
     NSLog (@ "touchesMoved");
}

Heading ##enter image description here

thank you

Upvotes: 0

Views: 236

Answers (3)

Vishnu
Vishnu

Reputation: 2243

As Benny Dalby told there is a way of making subclass of UIScrollView and can perform your touch event

In your scroll view subclass implementation file you can perform these function

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];


}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];


}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];


}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesCancelled:touches withEvent:event];
}

Upvotes: 1

Max_Power89
Max_Power89

Reputation: 1770

you need to use UIGestureRecognizer. You can add it directly in your viewController:

UITapGestureRecognizer *tap =
              [[UITapGestureRecognizer alloc] initWithTarget:myView action:@selector(yourSelector:)];
          [myView addGestureRecognizer:tapp];

Otherwise you can add it directly with the interface boulder: add gesture recognizer

after adding the gesture recognizer you can use it like a normal outlet.

Upvotes: 1

Benny Dalby
Benny Dalby

Reputation: 182

UIScrollView is immune to touchesEnded, touchesBegan, touchesMoved etc.That is it prevents these methods from getting called in the ViewControler.

Possibility 1 :

Use UIGestureRecognizerDelegates to implement touch in ScrollView

Possibility 2 :

Create a subclass of UIScrollView class and override the touchesBegan: and other touch methods

Hope it Helps!!!

Upvotes: 0

Related Questions