Conditions when drawRect rect! = Self.frame

I have a subclass of UIView in which I am doing some custom drawing. When drawRect:(CGRect)rect receives a call to rect.size , it is either (64, 63) or (63, 64); self.frame.size - (64, 64).

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

What conditions may cause some of these subclasses to have modified drawRect boundaries, but not others?

Extra tidbits:

  • self.opaque NO
  • self.transform is changing; I use it to rotate a UIView in increments of 90 degrees, but rotating the view does not change rect.size to sub calls on drawRect
+4
source share
1 answer

The direct passed drawRect is the direct one that the system asks you to do (dirtyRect) in your view coordinate system.

It can be self.bounds, or it can be another rect.

Generally, you should just ignore the parameter and draw yourself in self.bounds if your drawing is not very complex. Paying attention to the dirtyRect parameter that is passed is an optimization that should be ignored until you profile your application and determine that it is a hot spot.

+12
source

All Articles