3

我有一个类似网格的缩略图滚动视图,我首先初始化所有缩略图,然后将其框架设置为:

thumbnail.frame = CGRectMake(0, 0, 100, 100);

然后稍后willAnimateRotationToInterfaceOrientation,重新定位这些缩略图:

thumbnail.transform = CGAffineTransformMakeTranslation(posX, posY);

虽然在上述方法之后检查位置时:

NSLog(@"thumbnail frame x: %f", thumbnail.frame.origin.x);

它将返回包含变换操作的位置,而不是0,0

transform使用而不是设置一个新frameUIView作为重新定位的目的是否有真正的好处?

4

2 回答 2

1

主要好处是您可以使用更多类型的仿射变换,例如

  • CGAffineTransformTranslate
  • CGAffineTransformScale
  • CGAffineTransformRotate
  • CGAffineTransformInvert
  • CGAffineTransformConcat

但 frame struct 只设置框架。

其他注意事项:

1) In performance reasons assuming that CGAffineTransformMakeTranslation(posX, posY) changes only center property it is loos like it should work faster than changing the frame property but who knows. So for reposition purposes I would use this way or changing the center property.

2) In contrast of CALayer's transform the UIView's transform changes real position of the view.

于 2012-05-30T10:01:27.217 回答
0

Using the translation transform will move (translate) the view in the transformed perspective. That is, uf you first rotate the view, and then translates it, it will move in the direction relative to the rotation. For a simple reordering, I would suggest changing the center property instead. This way, you can still use the frame property in a meaningful way.

于 2012-05-30T10:08:37.280 回答