views:

387

answers:

10

I would like to do a transformation (rotation) to a UIImageView, I could just set the transform property of the view, but would setting the layer's transform make it faster? If so.. how can I achieve this?

assuming I have a UIImageView initialized with an image, can anyone help? would it be better have a UIVIew with a UIImageView in it?

+1  A: 

If you're doing a simple rotation, the speed difference is probably insignificant, but you can get access to a view's layer by doing:

view.layer

So, you can just use

view.layer.affineTransform = newTranform;

Ben Gottlieb
what do you mean by speed difference? it is never constant even if you specify the animation to be linear?
you asked if setting the layer's transform would make it faster; that's the speed difference I was referring to.
Ben Gottlieb
A: 

Hey Ben, this question is actually related to the previous question. Thank you tho!

I don't know how to do this rotation? Would it be ok if I ask you more details? I was going to try to have an UIImageView with its center in the middle-bottom of the screen and rotate it from there constantly. I was thinking if using NSTimer for this too since the rotation needs to be happening constantly.

A: 

You can do a constant rotation using a CAAnimation that auto repeats (I think; I haven't actually tried to do this exact thing, but similar stuff).

If one animation won't do it, certainly two will (have one rotate 180°, then when it ends, have another one fire to do the second 180°. This can be done on either the view or its layer. You'll definitely want to test this on a device for performance.

No need to use NSTimer; this is what CoreAnimation is built for.

Ben Gottlieb
A: 

Thanks Ben!

I was thinking of timers or threads actually. Because the animation's speed depends on how you are holding the phone (it uses the accelometer) and when you tap it (and hold), the animation's duration should go slower and when you release the finger (touch ends) it should stop completely. (complicated yes)

ideas would be greatly appreciated, your help is invaluable

I would still use CoreAnimation, but change the animation as your parameters change. Apple's already done the heavy lifting here, take advantage of their tools, don't go to the effort of rolling your own.
Ben Gottlieb
A: 

english grammar correction! I meant your help is greatly appreciated! sorry for the misunderstanding

A: 

Thank you! are there any good resources out there to learn in a not so hard way about Core Animation? the docs provided by Apple are really hard to follow. I've been reading coreanimation prog guide many times with not a big solid understanding.

also the idea of mixing a lot of C code with objective-C isn't fun at all

A: 

Check out Bill Dudney's Pragmatic Programmer book on Core Animation, Core Animation for Mac OS X and the iPhone.

Ben Gottlieb
A: 

Looks good, I will def buy it (you read it?)

thanks, by any chance do you know of any apps or examples where they show animation examples using only Core Animation on the layers? Not really sure which animation type is suitable for what I'm trying to do, was thinking of transaction animations or basic ones.. i'm not touching keyframe ones, they seem impossible to use.

A: 

I give up, Going to use UIImageViews instead...

A: 

How do you think this app was done? to create the way that scale animates? I'm trying to do something similar

http://www.madeupsoftware.com/trueweight/home.html