1

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?

Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421

2 Answers2

3

From the doc of .frame:

http://developer.apple.com/iphone/library/Resources/439/Images/icon_warning.gif 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
  • 510,854
  • 105
  • 1,084
  • 1,005
  • 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. – Dan Rosenstark Jun 10 '10 at 22:01
3

Change the "center" property instead.

tc.
  • 33,468
  • 5
  • 78
  • 96
  • 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`. – Dan Rosenstark Jun 11 '10 at 13:23
  • 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. Jun 11 '10 at 19:16
  • For the record, Apple documents `center` as being another way to set `frame` and states that `frame` is not reliable if a `transform` has been applied. So this is not the correct answer, regardless of whether it empirically seemed to work under whatever historic versions of iOS. KennyTM's answer is correct. – Tommy Aug 18 '14 at 18:55
  • No. Apple's wording is that setting `center` "changes the values of the `frame` properties [sic] accordingly", but also that setting `frame` "changes the point specified by the `center` property and the size in the `bounds` rectangle accordingly". The only reasonable way to interpret this is "if you set `center`, the value you next read from `frame` will reflect the change", and the warning is "don't read `frame` if you've set a non-identity `transform`", not "don't set `center`". – tc. Jan 29 '15 at 22:27