Re: Rotated and scaled CALayer
Re: Rotated and scaled CALayer
- Subject: Re: Rotated and scaled CALayer
- From: Andreas Grosam <email@hidden>
- Date: Thu, 21 Oct 2010 12:07:49 +0200
On Oct 21, 2010, at 10:56 AM, Rimas M. wrote:
> Hello list,
>
> I do not have a lot of practice with Core Animation, maybe that is the
> reason. I have a real annoying problem.
>
> All I want to do is:
> 1. Create CALayer
> 2. Set CGImage for its content
> 3. Depending on situation rotate and zoom in that layer (or its content)
>
> Looks like everything works, but I am getting "rotated" pixels
> (http://dl.dropbox.com/u/2030721/ForAppleList/Rotated Pixels.png).
> That is not what I want. I would like to get rotated content of image
> with "straight" pixels.
>
> I was trying to play with layer transform property, with layer
> delegate "- (void)drawLayer:(CALayer *)layer
> inContext:(CGContextRef)ctx" and by using CGContextRotateCTM etc.
> I have even tried to use layer and sublayer to split transforms (one
> layer scales, and other rotates) but result is always the same.
> Is there any way to achieve result I want? Currently the only way I know is:
> a) to rotate an image by drawing it to the bitmap context
> b) create new rotated CGImage from it
> c) and then draw it for scaling.
>
> But this way is quite slow. Is there a better one?
>
> Any help is very appreciate.
- You should add your new layer as a sublayer to the layer of the view-controller's view - or as a sublayer to any other layer than the controller view's layer.
- Usually, you "draw" the contents only once. However, when you set an *image* via the layers's contents property, you don't need to explicitly draw the layer - the layer draws the image for you, when it is required. So, just set the image as the layer's contents.
- You can scale/zoom the layers's contents by setting the layer's transform property accordingly. This uses Core Animation, which executes - if possible - on the GPU, and is therefore the fastest method. Note, this doesn't require the image to be "drawn" again (it requires "rendering").
You can create a suitable transform which scales AND zooms at once.
- A CALayer's properties are "animatable" (see Core Animation). In fact, changes in properties are animated by default. But you can define any animation, and CA nicely performs them for you.
- Using Core Graphics functions is *usually* not as fast as Core Animation (if a CA alternative exists). But certainly, CG has its use. So, if you want to scale and zoom interactively, use CA.
Regarding transforms, see also:
CATransform3DMakeRotation, CATransform3DMakeScale, CATransform3DConcat
Regards,
Andreas
>
> Best Regards,
>
> Rimas M.
> _______________________________________________
>
> 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
_______________________________________________
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