1

I have NSImageView inside NSScrollView on MAC. I subclass NSImageView and capture mouse down event.

But the coordinates keep changing depending if the NSScrollView is panned or zoomed even if I click on the same point in image.

How can I get a consistent mouse coordinate when zoomed or panned, here is my non working code.

-(void)mouseDown:(NSEvent *)theEvent
{
    NSPoint currentLocation = [theEvent locationInWindow];
    NSPoint locationInView = [scrollView convertPoint:currentLocation fromView:self];
    [super mouseDown:theEvent];
}

Anybody???

N S
  • 303
  • 4
  • 17

1 Answers1

1

I had the same question and found the answer in this stack overflow question/answer

NSPoint aLocationInSelf = [self convertPoint: [anEvent locationInWindow] fromView: nil];
Community
  • 1
  • 1
user2962499
  • 486
  • 6
  • 10