• 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: Graham Cox <email@hidden>
  • Date: Fri, 25 Jan 2013 10:12:41 +1100

On 25/01/2013, at 12:42 AM, Matt Neuburg <email@hidden> wrote:

> 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 );


Thanks for chipping in Matt, but unfortunately you're wrong ;-)  Your reasoning seems sound but that's how transforms trip you up - they are rarely intuitive and seemingly are hard to tame.

The correct code is:

	CGRect br = self.bounds;
	CGPoint anch = self.anchorPoint;

	CGAffineTransform tfm = CGAffineTransformMakeTranslation( self.position.x, self.position.y );

	tfm = CGAffineTransformConcat( self.transform, tfm ); //<----- take care that tfm is the second parameter
	return CGAffineTransformTranslate( tfm, -(br.origin.x + anch.x * br.size.width), -(br.origin.y + anch.y * br.size.height));


 On the face of it this even seems equivalent to your suggestion, but I can tell you the result is not the same.

I have eventually stumbled upon the right result which correctly transforms down through a series of nested layers and back up again. Don't ask me how it works or I'll start to whimper.

--Graham





_______________________________________________

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: Matt Neuburg <email@hidden>
References: 
 >Re: Coordinate conversions in CALayer (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: Getting mouse loc in flagsChanges method
  • Next by Date: Re: Getting mouse loc in flagsChanges method
  • Previous by thread: Re: Coordinate conversions in CALayer
  • Next by thread: Re: Coordinate conversions in CALayer
  • Index(es):
    • Date
    • Thread