views:

279

answers:

1

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
+4  A: 

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.

Peter N Lewis