创建一个Square Uiview Object 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

我无法弄清楚这种变化框架值的逻辑,尤其是最后一个。谁能启发我?谢谢。

有帮助吗?

解决方案

在Uiview类参考中,您可以看到 这里 您不应该将视图的框架设置为具有变换属性与不同的属性 CGAFFINETRANSFORMIDENTITY.

如果要更改转换视图的位置,则应使用 中央 财产。如果要调整尺寸,则应使用 边界 财产。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top