• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: PDFKit: translate point coordinates from view coordinates into page coordinates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PDFKit: translate point coordinates from view coordinates into page coordinates


  • Subject: Re: PDFKit: translate point coordinates from view coordinates into page coordinates
  • From: Antonio Nunes <email@hidden>
  • Date: Tue, 27 Mar 2012 14:17:06 +0100

On 27 Mar 2012, at 12:19, Nick wrote:

> I would like to place a PDFAnnotation onto a PDF page in a place where
> the user clicked with the mouse.
[...]
> NSPoint locationInView = [self convertPoint:[theEvent
> locationInWindow] fromView:[[self window] contentView]];

You are receiving the event location in the window, but you are converting based on the content view. Pass NULL in fromView: to translate from window coordinates to local coordinates. Then let PDFView do the heave lifting for you to translate that point to a point on a page.


To convert the point to page coordinates use something to the effect of:

-(void)mouseDown:(NSEvent *)event
{
	NSPoint 	mouseDownPoint = [self convertPoint:[event locationInWindow] fromView:NULL];
	PDFPage 	*mouseDownPage = [self pageForPoint:mouseDownPoint nearest:NO];
	NSPoint		pagePoint = [self convertPoint: mouseDownPoint toPage:mouseDownPage];
	...
}

The above should work at any scale factor.

-António

-----------------------------------------------------------
And you would accept the seasons of your
heart, even as you have always accepted
the seasons that pass over your field.

--Kahlil Gibran
-----------------------------------------------------------




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >PDFKit: translate point coordinates from view coordinates into page coordinates (From: Nick <email@hidden>)

  • Prev by Date: Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
  • Next by Date: Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
  • Previous by thread: Re: PDFKit: translate point coordinates from view coordinates into page coordinates
  • Next by thread: Rotating CALayer on iDevice rotation
  • Index(es):
    • Date
    • Thread