简体   繁体   English

drawRect的rect!= self.frame时的条件

[英]Conditions when drawRect's rect != self.frame

I have a UIView subclass that I am doing some custom drawing in. When drawRect:(CGRect)rect is getting called rect.size is either (64, 63) or (63, 64); 我有一个UIView子类,我正在做一些自定义绘图。当drawRect:(CGRect)rect被调用时, rect.size是( rect.size )或(63,64); self.frame.size is (64, 64). self.frame.size是(64,64)。

I have multiple instances of this subclass, most of which get the expected (64, 64) size for the drawRect parameter. 我有这个子类的多个实例,其中大部分都获得了drawRect参数的预期(64,64)大小。

What are conditions that may cause some of these subclasses to have modified drawRect bounds but not others? 什么条件可能导致这些子类中的某些子类具有修改的drawRect边界而不是其他子类?

Additional tidbits: 额外的花絮:

  • self.opaque is NO self.opaque是NO
  • self.transform does vary; self.transform确实有所不同; I use it to rotate the UIView in 90-degree increments, but rotating the view does not change rect.size on subesquent calls to drawRect 我使用它以90度的增量旋转UIView,但旋转视图不会更改rect.sizedrawRect后续调用

The rect passed to drawRect is the rect that the system is asking you to draw (dirtyRect) in your view's coordinate system. 传递给drawRect的rect是系统要求您在视图的坐标系中绘制(dirtyRect)的矩形。

It can be self.bounds, or it can be a different rect. 它可以是self.bounds,也可以是不同的rect。

Generally, you should simply ignore the parameter and draw yourself in self.bounds, unless your drawing is very complex. 通常,您应该忽略参数并在self.bounds中绘制自己,除非您的绘图非常复杂。 Paying attention to the dirtyRect parameter passed in is an optimisation which should be ignored until you've profiled your app and determined it is a hot spot. 注意传入的dirtyRect参数是一个优化,在您分析应用程序并确定它是热点之前,应该忽略该优化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM