为什么UIView中有框架矩形和边界矩形? [英] Why is there an frame rectangle and an bounds rectangle in an UIView?

查看:90
本文介绍了为什么UIView中有框架矩形和边界矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然在漆黑的夜晚很晚,但我不明白为什么有两个不同的矩形:框架和边界。

Well although it's late in the dark night, I don't get it why there are two different rectangles: frame and bounds.

就像我理解的那样,只需要一个矩形即可完成所有工作。将View本身相对于另一个坐标系定位,然后将其内容剪切为指定的大小。你还会用两个矩形做什么?他们如何与彼此互动?

Like I understand it, one single rectangle would have been just enoug to do everything. Positioning the View itself relative to another coordinate system, and then clipping it's content to a specified size. What else would you do with two rectangles? And how do they interact with eachother?

有没有人有一个很好的解释?来自苹果医生的那个拿着水果的孩子不太适合理解。

Does anyone have a good explanation? The one from the apple docs with the kid holding the fruit is not pretty good for understanding.

推荐答案

这是备忘单:


  • frame 是视图 的地方(相对于超级视图)

  • bounds 是允许视图绘制的地方(相对于自身)

  • frame is where the view is (with respect to the superview)
  • bounds is where the view is allowed to draw (with respect to itself)

更多澄清:

如果要将视图定位在其超级视图中,你几乎总是改变帧的原点。

If you are positioning the view in its superview, you almost always change the frame origin.

如果你正在绘制UIView绘制的地方,你几乎总是修改它的边界。

If you are clipping where the UIView is drawing, you almost always modify its bounds.

请注意,您可以拥有大于帧的边界。也就是说,你可以画出你所在位置的外线。

Note that you are allowed to have bounds that is bigger than the frame. That is, you can draw "outside the lines" of where you are.

这篇关于为什么UIView中有框架矩形和边界矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆