views:

29

answers:

2

This code works to rotate:

  CGAffineTransform transform = CGAffineTransformMakeRotation(radians(lastAngle++)); 
  anImage.transform = transform;  

and this code works to move my UIImageView

  CGRect frame = [anImage frame];
  frame.origin.x+=1;
  frame.origin.y+=1;
  [anImage setFrame:frame];

but when I combine them, the image stretches out increasingly on each run through. Perhaps the frame should not be modified like this?

+1  A: 

From the doc of .frame:

Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.


The .transform property can be used for translation too, see CGAffineTransformMakeTranslation or CGAffineTransformTranslate.

KennyTM
@KennyTM, thanks for that: the .transform works, but then the movements have a different/weird anchor point... in any case, now I realize that I have to put my view in a view (I think). Trying that now.
Yar
Wow, that worked.
Yar
+1  A: 

Change the "center" property instead.

tc.
Center property for the transform worked nicely, thanks. So two options are 1. put the view in a view, and move the outer one while rotating the inner one and 2. change the center prop on the `CGAffineTransform`.
Yar
Pick the one that makes more sense. If you change the transform's translation as well, both the view center and frame become meaningless on their own. This is fine if you'll never need to change the view position again. Also remember that you'll need to handle device rotation.
tc.