Graphics Reference
In-Depth Information
Figure 5.18 Actual result of opposite rotations around the Y axis
To draw an analogy, it's just like tilting the screen away when you are playing a 3D game.
You might see a wall in front of you in the game, but tilting the screen won't allow you to
peer around the wall. The scene displayed on the screen doesn't change depending on the
angle at which you look at it; neither do the contents of a layer.
This makes it difficult to create very complex 3D scenes using Core Animation. You cannot
use the layer tree to build a hierarchical 3D structure—any 3D surfaces in the same scene
must be siblings within the same layer because each parent flattens its children.
At least, that's true if you use regular CALayer instances. There is a CALayer subclass
called CATransformLayer designed to deal with this problem. This is covered in
Chapter 6, “Specialized Layers.”
Solid Objects
Now that you understand the basics of positioning layers in 3D space, let's try constructing
a solid 3D object (well, technically a hollow object, but it will appear solid). We'll create a
cube by using six separate views to construct the faces.
For the purposes of our example, the cube faces are arranged in Interface Builder (see
Figure 5.19). We could create the faces in code, but the advantage of using Interface
Builder is that we can easily add and arrange subviews within each face. Remember that
these faces are ordinary user interface elements that can contain other views and controls.
They are fully fledged, interactive parts of our interface, and will remain so even after we
fold them up into a cube.
 
Search WWH ::




Custom Search