Have you ever really stopped to look at the view hierarchy that we create?
The diagram below shows the view hierarchy that we create in that tutorial. The view hierarchy is different than the object composition that we create. We create several objects and store the layers and views as attributes of those objects, but the way that those objects are saved as attributes is different than how we stack them in the hierarchy. For example, we create the variables _rootLayer, _paneLayer, and _borderLayer as attributes of the PageView class, but when we initialize the PageView object, we add the _paneLayer and the _borderLayer as subLayers of the _rootLayer variable.
The View Hierarchy of the Scrapbook Project. Diagram created in MagicDraw PE |
The visual depiction of the view hierarchy diagrammed above. |
There are two view hierarchies in this diagram actually. Each view hierarchy is rooted at a CPWindow object. In this diagram, the two roots are both named "theWindow." One root is a CPWindow, and this view fills the page and forms the display on which we see the image. The other root is a CPPanel, and it floats on top of the other window in order to display the controls that we use to manipulate the image.
From each of these roots, every object seen in the tree is either a derivative of CPView or CALayer.
We are told that the difference between CPView and CALayer is that the CALayer has advanced graphic handling properties. This implies that if we are not performing advanced graphic manipulations that we ought be able to create an entire application out of CPViews without any CALayers. Every CPWindow is created with a CPView to display it's primary content, making it impossible to have a view hierarchy without this object. However, we see in this tutorial that the CALayer requires the CPView in order to display itself; no layer is hosted from a CPWindow directly, so we might infer that CALayers are not necessary in any project. This is why we study the CPView first.
No comments:
Post a Comment