0

when I use: ImageView.transform = CGAffineTransformRotate(ImageView.transform, rotation); everytime I rotate imageView and I NSLog(@"x:%f y:%f", ImageView.frame.orgin.x, ImageView.frame.orgin.y), x and y always change value?? Why?

Huỳnh Phong
  • 31
  • 1
  • 6

2 Answers2

0

Well the .frame.origin is the top left corner of you UIImageView and since you are rotating it the top left corner is moving. If you access the .center it should stay the same.

Majster
  • 3,611
  • 5
  • 38
  • 60
  • when I move view using: CGAffineTransformTranslate(view.transform, difx, dify); And I get: view.center.x, this value not changes when I move it?? – Huỳnh Phong Dec 09 '12 at 12:09
  • @HuỳnhPhong Center changes when you move the view. By setting the translation transform you are just displaying the content with offset to the position of the view. Translation _does not_ move the view. – Tricertops Dec 09 '12 at 12:31
  • Thanks! How to I get center point current when I move view using CGAffineTransformTranslate ? – Huỳnh Phong Dec 09 '12 at 12:34
  • To get the translation: `view.transform.tx` and `view.transform.ty`. These coordinates are relative to view's `center`, so to get absolute X: `view.center.x + view.transform.tx`. – Tricertops Dec 09 '12 at 13:04
0

The UIView documentation states that

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

regarding the transform property of a UIView. Since you are assigning to the transform it is most likely not the identity transform any more, hence the frame value is undefined, and should be ignored.

Hjalmar
  • 989
  • 8
  • 16
  • This is strange, because for me `frame` always worked as bounding box of the rotated view. – Tricertops Dec 09 '12 at 12:29
  • I agree it sounds strange, and I have also used the frame property as "the way the superview sees it", and then the bounds gives the actual rotated view coordinates. I saw this documentation for the first time today. – Hjalmar Dec 09 '12 at 12:39