【发布时间】:2011-08-13 18:07:21
【问题描述】:
创建一个方形 UIView 对象 testView_,并将其添加到 viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
CGRect initialRect = testView_.frame;
NSLog(@"before rotation: w %f h %f x %f y %f", initialRect.size.width, initialRect.size.height, initialRect.origin.x, initialRect.origin.y);
testView_.transform = CGAffineTransformMakeRotation(0.1);
NSLog(@"after rotation: w %f, h %f, x %f, y %f", testView_.frame.size.width, testView_.frame.size.height, testView_.frame.origin.x, testView_.frame.origin.y);
testView_.frame = initialRect;
NSLog(@"reassign: w %f, h %f, x %f, y %f", testView_.frame.size.width, testView_.frame.size.height, testView_.frame.origin.x, testView_.frame.origin.y);
}
我在控制台中收到这个:
2011-04-27 12:30:32.492 Test[31890:207] before rotation: w 100.000000 h 100.000000 x 20.000000 y 20.000000
2011-04-27 12:30:32.494 Test[31890:207] after rotation: w 109.483757, h 109.483757, x 15.258121, y 15.258121
2011-04-27 12:30:32.495 Test[31890:207] reassign: w 117.873589, h 100.000000, x 11.063205, y 20.000000
我无法弄清楚帧值变化背后的逻辑,尤其是最后一个。任何人都可以启发我吗?谢谢。
【问题讨论】:
-
我不完全确定这个答案。所以我把它作为评论..当我们旋转一个视图时,比如 B,它是 A 的子视图,只有 B 的变换被改变。 Frame 是根据在 parentView 中的位置来考虑的,即 B 在 A 中的位置。所以当我们旋转 B 时,B 在 A 中的总正方形空间(在 A 的变换中计算)增加。这就是第二个日志的原因..现在第三个你强行将原始框架给 B,但是旋转的 B 现在的大小比原始大小强,这迫使 parentView A 通过仅保持一个方向(y 和高度/x 和宽度)恒定来自动调整 B .
-
好问题..我也想知道..
-
你没有答案...太糟糕了..
标签: iphone uikit frame cgaffinetransform