• 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: Coordinate conversions in CALayer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coordinate conversions in CALayer


  • Subject: Re: Coordinate conversions in CALayer
  • From: Matt Neuburg <email@hidden>
  • Date: Thu, 24 Jan 2013 05:42:41 -0800

> Date: Thu, 24 Jan 2013 12:01:28 +1100
> From: Graham Cox <email@hidden>
> To: "email@hidden Dev" <email@hidden>
> Subject: Re: Coordinate conversions in CALayer

> Boiling down my problem to its bare essentials, why are these two bits of code not equivalent?
>
>
>
> 	CGContextTranslateCTM( ctx, pos.x, pos.y );
> 	CGContextConcatCTM( ctx, layer.transform );
> 	CGContextTranslateCTM(ctx, -(br.origin.x + anch.x * br.size.width), -(br.origin.y + anch.y * br.size.height));
>
> The above works correctly, but below, which I thought should do the same, does not, if the layer.transform property is not the identity matrix:
>
>
>
> 	CGAffineTransform tfm = CGAffineTransformMakeTranslation( pos.x, pos.y );
> 	tfm = CGAffineTransformConcat( tfm, layer.transform );
> 	tfm = CGAffineTransformTranslate( tfm, -(br.origin.x + anch.x * br.size.width), -(br.origin.y + anch.y * br.size.height));
>
> 	CGContextConcatCTM( ctx, tfm );

They are not equivalent because the first one starts with CGContextTranslateCTM but the second one starts with CGAffineTransformMakeTranslation. In other words, the first one begins by translating the current transform. The second one begins with a plain vanilla translation. The affine transform equivalent of CGContextTranslateCTM is CGAffineTransformTranslate. You might want to say this:

CGAffineTransform tfm = CGAffineTransformTranslate( layer.transform, pos.x, pos.y );

m.

--
matt neuburg, phd = email@hidden, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com


_______________________________________________

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

  • Follow-Ups:
    • Re: Coordinate conversions in CALayer
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: Hover button and tracking area questions
  • Next by Date: Re: Hover button and tracking area questions
  • Previous by thread: Re: Coordinate conversions in CALayer
  • Next by thread: Re: Coordinate conversions in CALayer
  • Index(es):
    • Date
    • Thread