ios - 当我改变 UIVIew 的 bounds.size.height 时 frame.origin.y 改变

标签 ios uiview frame bounds

(我的英文不是很好哈哈)

我定义了一个 UIView 对象作为 subview ,当我改变 subview.bounds.size.height 时,subview.frame.origin.y 改变了,我的代码有什么问题吗?

这是我的代码:

- (IBAction)touch
{
    static int i = 1;
    NSLog(@"%d: Bounds: %@", i, NSStringFromCGRect(self.subView.bounds));
    NSLog(@"%d: Frame: %@", i, NSStringFromCGRect(self.subView.frame));
    self.subView.bounds = CGRectMake(0.f, 0.f, self.subView.bounds.size.width, self.subView.bounds.size.height + 50);
    NSLog(@"%d: Bounds: %@", i, NSStringFromCGRect(self.subView.bounds));
    NSLog(@"%d: Frame: %@", i, NSStringFromCGRect(self.subView.frame));

    i++;
}

系统输出:

2011-12-23 12:11:29.316 Angry[7959:f803] 1: Bounds: {{0, 0}, {320, 100}}
2011-12-23 12:11:29.318 Angry[7959:f803] 1: Frame: {{0, 0}, {320, 100}}
2011-12-23 12:11:29.319 Angry[7959:f803] 1: Bounds: {{0, 0}, {320, 150}}
2011-12-23 12:11:29.320 Angry[7959:f803] 1: Frame: {{0, -25}, {320, 150}}

2011-12-23 12:11:30.920 Angry[7959:f803] 2: Bounds: {{0, 0}, {320, 150}}
2011-12-23 12:11:30.921 Angry[7959:f803] 2: Frame: {{0, -25}, {320, 150}}
2011-12-23 12:11:30.922 Angry[7959:f803] 2: Bounds: {{0, 0}, {320, 200}}
2011-12-23 12:11:30.923 Angry[7959:f803] 2: Frame: {{0, -50}, {320, 200}}

2011-12-23 12:11:32.080 Angry[7959:f803] 3: Bounds: {{0, 0}, {320, 200}}
2011-12-23 12:11:32.082 Angry[7959:f803] 3: Frame: {{0, -50}, {320, 200}}
2011-12-23 12:11:32.083 Angry[7959:f803] 3: Bounds: {{0, 0}, {320, 250}}
2011-12-23 12:11:32.084 Angry[7959:f803] 3: Frame: {{0, -75}, {320, 250}}

最佳答案

改变边界确实会影响框架:

Although you can change the frame, bounds, and center properties independent of the others, changes to one property affect the others in the following ways:

  • When you set the frame property, the size value in the bounds property changes to match the new size of the frame rectangle. The value in the center property similarly changes to match the new center point of the frame rectangle.
  • When you set the center property, the origin value in the frame changes accordingly.
  • When you set the size of the bounds property, the size value in the frame property changes to match the new size of the bounds rectangle.

关于ios - 当我改变 UIVIew 的 bounds.size.height 时 frame.origin.y 改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8612265/

相关文章:

ios - .xib 文件中的多语言标签更改。

ios - 改变UIView位置的简单方法?

php - 难题 : How to access ffmpeg_php getFrame in Imagick without convert to GD?

每帧调用的Java函数

javascript - 在 iPad 上播放 HTML5 视频并寻找

objective-c - 从 UISearchBar 对 NSArray 执行搜索

iOS 图表 - 仅在突出显示时绘制值

ios - UIAlertView subview 定位

iphone - 自动更改 View 的布局

当 subview 调整大小时,iOS LayoutSubviews 被多次调用