创建一个正方形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
我不能弄清楚frame值变化背后的逻辑,特别是最后一个。有谁能开导我吗?谢谢。
发布于 2011-05-03 19:15:13
在UIView类参考中,您可以看到不应使用不同于CGAffineTransformIdentity.的transform属性设置视图框架的here
如果你想改变转换后的视图的位置,你应该使用center属性。如果你想调整大小,你应该使用边界属性。
https://stackoverflow.com/questions/5802830
复制相似问题