View Full Version : View coordinates origin changes in a different controller than the views

Nov 5, 2009, 10:41 AM

I found this a bit wired:

This is my touchesEnded method:

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

NSLog(@"x-value %i", (int)(point.x));
NSLog(@"y-value %i", (int)(point.y));


Here is the thing, if I use this method in my custom view class, it will use the top-left corner as the origin corner (i.e. position 0, 0).

Touching around the top-left corner produces something like this.

x-value 53
y-value 77

If I use it in my controllers class, it's the same as well.

But here it is, I am using another controller class to position this view and another view in the screen. Hence I need to have touchesEnded in this class. When doing that, it will treat the lower left corner as the origin corner.

Touching around the bottom-left corner produces something like this in this case:

x-value 64
y-value 77

How come, and how do I get around it?

In IB the top-left corner is set as the origin for all views, at least to my understanding (the top left corner in the Size & Position field is marked with the two arrows pointing to the right and down.

Thanks in advance!