Empty UIView with minimal drawRect: overhead
I have an application that has three nested views that are mechanically important but have no visuals:
- Vanila UIView, which has no content of its own and is just used as a node for CALayers.
- The UIScrollView (which is queried for its origin and used to position the CALayers in 3d: I really only use this view to replicate exactly the "mechanic" scrolling view),
- Scroll view content: UIView subclass. It just collects touch events and passes them to the delegate - all that matters is its UIResponder mechanism.
The UIView host CALayers are a child of the UIImageView, which is the background image over which CALayers are drawn.
I would really like to make sure that none of these empty UIViews have any associated overhead or layout (in time or storage), or if it is not possible, to get this overhead as little as possible, and also figure it out so that I could decide if I should try a different approach.
In the interface builder, I have set all views so as not to clear their context before drawing. I didn't make them opaque because they are definitely not opaque - they are completely transparent. I found that I needed the scroll content to display a transparent transparent color (again in IB, setting the opacity of the background color to zero) and that says it is drawn, which is not what I want.
So, in short, I don't really know much about what's and what's not working out (does anyone know a tool like Quartz Debug for iPhone / simulator?), Or how to stop things from stopping from drawing.
Advice would be very welcome! Thanks Benjon
Apart from the UIScrollView, which I can't talk about, your other views shouldn't get in the way of drawing overhead too much unless you manually call setNeedsDisplay or set your DisplayOnBoundsChange property level to YES. The views are drawn once and their layers are cached on the GPU at that time. Redrawing is expensive, but it only happens if you manually start it using the tools described above. These views and layers will use memory, so this is a concern, especially if the encompassing views get very large (especially around 2048 x 2048). Unfortunately, there is nothing you can do about it.
As a suggestion, if all you are doing is rotating and scaling layers in 3-D, I might suggest you take a look at some sample code I wrote for 3-D rotation and scaling on iPhone using Core Animation. It is based on code written by Bill Dudney, where touch events are handled in one-touch motions and two-finger pinch gestures, and then used to manipulate layers in 3-D. This can simplify your code by removing the need for a UIScrollView and your custom content view.
a source to share