How do I access the presentation layer?

I would like to apply transform (rotation) to UIImageView

. I could just set a property transform

for the view, but wouldn't set the layer transform

to make it faster? If so, how can I achieve this?

Assuming I have UIImageView

it initialized with an image, can anyone help? Wouldn't it be better to have UIVIew

with UIImageView

in it?

+1


source to share


2 answers


If you're doing a simple rotation, the speed difference is probably negligible, but you can access the view layer by running:

view.layer



So you can just use

view.layer.affineTransform = newTranform;

+1


source


You can do constant rotation with CAAnimation, which automatically repeats (I guess I haven't actually tried to do this exact thing, but similar stuff).

If one animation doesn't do that, of course, there will be two (one 180 ° rotation, and then when it's finished, you have another fire to make the second 180 °. This can be done either in the view or on its layer. You will definitely want to test this on a device for performance.



You don't need to use NSTimer; this is what CoreAnimation is built for.

0


source







All Articles