Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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); self.frame.size is (64, 64).

I have multiple instances of this subclass, most of which get the expected (64, 64) size for the drawRect parameter.

What are conditions that may cause some of these subclasses to have modified drawRect bounds but not others?

Additional tidbits:

  • self.opaque is NO
  • self.transform does vary; 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
like image 555
fbrereto Avatar asked Dec 17 '22 06:12

fbrereto


1 Answers

The rect passed to drawRect is the rect that the system is asking you to draw (dirtyRect) in your view's coordinate system.

It can be self.bounds, or it can be a different rect.

Generally, you should simply ignore the parameter and draw yourself in self.bounds, unless your drawing is very complex. 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.

like image 190
Peter N Lewis Avatar answered Dec 19 '22 21:12

Peter N Lewis