0

I'm working on iPad app. My UIViewController contains only a custom UIView with a size of 500wx500h.

I implemented the touches methods both in the UIViewController and the custom UIView in order to call the UIViewController touches methods when we touch all around the custom UIView and call the custom UIView touches methods when we touch inside it.

UIViewController touchesMoved :

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.view];

    NSLog(@"TEST"); // Added during edition
    if (!CGRectContainsPoint(self.drawingView.frame, point)) {
        NSLog(@"UIVIEWCONTROLLER");
    }

}

Custom UIView touches Moved :

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"CUSTOM VIEW");
}

When I'm touching the custom UIView moving my finger, CUSTOM VIEW is logged until I removed the finger on the screen. On the other hand, when I'm touching outside of the custom UIView, the UIVIEWCONTROLLER is called only one time in the touchesMoved method.

Am I missing something wrong ?

EDIT : I added a log in my UIViewController touchesMoved method. When I touch inside the custom view, it logs the TEST during all the touching phase. But when I touch outside, I get the same behaviour.

Seb
  • 545
  • 9
  • 29
  • what is `drawingView`? you said that your controller has just got one view, but it should have at least two: `self.view` and `drawingView`... could it be the former is hijacking the touches? – sergio Jan 09 '13 at 09:53
  • My UIViewController contains his own view and an other custom UIView (which is called drawingView). – Seb Jan 09 '13 at 10:04

2 Answers2

0

add exclusiveTouch property to your view to disable multi touches

your view.exclusiveTouch=YES;
NANNAV
  • 4,875
  • 4
  • 32
  • 50
  • I try to set it on the custom view firstly and on the uiviewcontroller view then but both don't work :/ – Seb Jan 09 '13 at 10:19
0

There is some likeliness that your self.view is intercepting touches and handling them, so they will not make it through to the view controller. You could try doing either of 2 things (or both) and see if it works:

  1. self.view.exclusiveTouch = NO;

  2. self.view.userInteractionEnabled = NO;

I would also try to call [super touchesMoved: touches withEvent: event];

Hope it helps.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • `self.view.exclusiveTouch = NO;` had no effect. But `self.view.userInteractionEnabled = NO;` improved a bit the bahaviour. Instead of getting one `UIViewController` log, I get 7 `UIViewController`. The touches methods seems to be called only 7 times and stop to be called then. – Seb Jan 09 '13 at 10:39
  • Do you understand why ? :/ – Seb Jan 09 '13 at 10:40
  • as I said, there is some view intercepting the touches. I think you should also try and call `super` implementation of `touchesMoved`... maybe not calling it may make the touch "die" in the controller code after some time. – sergio Jan 09 '13 at 10:42
  • btw, you don´t explain what you are trying to achieve... maybe be there are better and easier approaches to that... – sergio Jan 09 '13 at 10:46