Search code examples
iphonexcodeuitouch

UITouch not return the correct position


I have a problem...

I want to get the UITouch position in a sigle view below the main view.

My code is:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    CGPoint previous = [[touches anyObject] previousLocationInView:toolBarView];
    CGPoint current = [[touches anyObject] locationInView:toolBarView];
}

The problem is that it returns the position in any view instead of toolbarView.

What's the matter?


Solution

  • U might want to correct

    CGPoint current = [[touches anyObject] locationInView:toolBarView];
    

    to:

    CGPoint current = [[touches anyObject] locationInView:[toolBarView view]];