我正在努力创建我的第一个自定义 UIView 并学习 drawRect 方法的语义。
我遇到过建议(对我来说有意义的建议)仅在CGRect<的范围内绘制/code> 作为参数传入,而不是总是在 UIView
的 bounds
内绘制所有内容:
- (void)drawRect:(CGRect)aRect {
// draw, draw, draw...
}
我现在想要找出的是是否有关于什么的任何限制bounds
和传入的 aRect
之间存在关系。特别是,我想知道 aRect
是否保证完全位于 < code>bounds,或者是否可以延伸到bounds
之外。
如果我的 UIView
之外的某些代码传递,例如,将一个非常大的 CGRect 传递到 setNeedsDisplayInRect:(NSRect)invalidRect
中,那么底层代码是否会盲目地将相同的 CGRect 传递到我的drawRect
方法,或者它是否进行某种交集并始终传入一个合理的矩形?
我在任何文档中都没有找到这个问题的答案。这是我根本不应该担心的事情吗?或者我应该总是自己将 bounds
和 aRect
相交?
I'm working on creating my first custom UIView and learning about the semantics of the drawRect method.
I have encountered advice (advice that makes sense to me) to only draw within the scope of the CGRect
that is passed in as an argument, rather than always drawing everything within the UIView
's bounds
:
- (void)drawRect:(CGRect)aRect {
// draw, draw, draw...
}
What I'm trying to find out now is whether there are any constraints about what relationship there is between bounds
and the aRect
that gets passed in. In particular, I'm wondering if aRect
is guaranteed to be entirely inside bounds
, or whether it may extends outside of bounds
.
If some code outside of my UIView
passes, for example, a very large CGRect into setNeedsDisplayInRect:(NSRect)invalidRect
, will the underlying code just blindly pass the same CGRect into my drawRect
method, or does it do some sort of intersection and always pass in a sensible rectangle?
I haven't found an answer to this in any documentation. Is this something I shouldn't even worry about? Or should I always intersect bounds
and aRect
on my own?
发布评论
评论(1)
来自查看编程指南:
您不会被要求在您的视野之外进行绘制。即使是这样,也应该设置剪辑矩形,以使绘图不会产生任何效果。
From the View Programming Guide:
You won't be asked to draw outside your view. Even if you were, the clip rect should be set such that the drawing would have no effect.