Objective-c – convertPoint:

objective-c

I'm learning Objective-C and Cocoa (in fits and starts when time allows) so be gentle OK.

A example app has the following lines:

NSPoint down = [mouseEvent locationInWindow];
//...some other stuff
NSPoint p = [self convertPoint:down fromView:nil]; 

It then proceeds to use p for a drag and drop operation (using the pasteBoard). But, what I don't get is this is all in one view, why not just use down, why do a convertPoint: ? Or have I missed something basic?

Thanks!

Best Solution

The point "down" is in the window's coordinate system — it starts in the corner of the window. The point "p" is in the view's coordinate system. Unless this view's origin happens to be exactly at the window's origin and neither has had its coordinate system transformed (say, with setBounds:), the two points will not be in the same place.

Related Question