drsquidop
drsquidop

Reputation: 438

problem changing center of rotation without moving subview in view

I have a UIImageView subview inside another view (main view). Both views are the same size. and are aligned. I want to rotate the subview inside the main view, but i don't want the center of rotation to be the center of the views. The reason is that the subview is a wheel that turns, the wheel is not in the center of the main view.

I assumed you change the center of the subview to the actual center point of the wheel, then rotate. But changing the center causes the subview to translate in the main view before the rotation occurs.

I want to change the point of rotation in the subview without translating it.

Does anyone know how to do this? BTW: this will be animated.

Upvotes: 0

Views: 522

Answers (2)

drsquidop
drsquidop

Reputation: 438

What I ended up doing was resizing the source art for the subview (wheel) to be smaller and centered around the wheels axis. Then there is no problem. Previously for prototyping and conveneince, I had kept all layers in my stack of art the same size to simplify export from photoshop. But this is not the way you would want to go to production anyway. So in this case, it is the better long term solution.

However, it would be nice to have a general solution for UIImageView to handle offset center points where the center of the subview is offset from the center of rotation.

Upvotes: 0

meronix
meronix

Reputation: 6176

I don't know if there is already a property for that,

but an easy way could be this: why don't you use an invisible view between the main view and the UIImage? then you have the mainView, its invisible subview, and as a subview of the invisible view your UIImage.

Now, for example, you can move the center of the invisible 100 pixel to the left, and the UIImage 100 pixel to the right, so the image and the main view have again the center in common, but now you can rotate the invisible view (and with it the image) around its not aligned center

luca

Upvotes: 2

Related Questions