首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在iPhone中旋转后UIView帧的奇怪行为

在iPhone中旋转后UIView帧的奇怪行为
EN

Stack Overflow用户
提问于 2011-04-27 18:47:41
回答 1查看 7K关注 0票数 17

创建一个正方形UIView对象testView_,并在viewDidLoad中添加以下内容:

代码语言:javascript
复制
- (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);
}

我在控制台中收到以下内容:

代码语言:javascript
复制
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值变化背后的逻辑,特别是最后一个。有谁能开导我吗?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-03 19:15:13

在UIView类参考中,您可以看到不应使用不同于CGAffineTransformIdentity.的transform属性设置视图框架的here

如果你想改变转换后的视图的位置,你应该使用center属性。如果你想调整大小,你应该使用边界属性。

票数 36
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5802830

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档