How I force a "container" UIView to have no CALayer?
I am trying to conserve memory consumption in my visualization about. I have a scrollView with a containerView that contains some child views. I would like to eliminate the CALayer of the scrollView and containerView. So, just the child views consume memor开发者_如何学Cy during redraws, etc.
How do I do this?
Thanks, Doug
All UIViews and UIView subclasses on the iPhone are backed by CALayers. There isn't really much you can do to avoid this because it's an assumption made by UIKit. (In Cocoa for Mac, you can specify which views have CALayers, though!)
While you might be able to hack a few things and destroy the CALayers of certain views, I wouldn't recommend it. I've written some pretty complex painting apps, and I've never had a problem with CALayers consuming large amounts of memory. Remember, you can safely use about 25MB of memory before your app receives a memory warning. If you're seeing your app churn through large amounts of memory used and you're just drawing, there's probably another problem.
Hope that helps,
Ben
My container layer is only 1x1 points large, and therefore uses very little memory. (I haven't tried 0x0 and don't know if that'll work.)
With clipsToBounds
== NO
(the default), all the subviews are still visible, even though they're "sticking out" of their parent view.
If your subviews need to receive events you'll need to overwrite -pointInside:withEvent:
to return YES
for points inside the "real" bounds of your container view.
精彩评论