On 25/01/2013, at 12:42 AM, Matt Neuburg <m...@tidbits.com> 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to