Graphics Reference
In-Depth Information
[reflectionLayer
setValue
:DegreesToNumber(180.0f)
forKeyPath
:
@”transform.rotation.x”
];
This sets the layer's transform to 180 degrees from its original to give you the flipped
image effect.
Finally, a gradient layer is applied to the reflection layer. Because we want to use the
gradient layer as a mask, the gradient layer uses the same bounds and position as the
reflection layer and is added to the layer tree of the reflection layer. You can adjust the
way the gradient layer displays by altering its
startPoint
and
endPoint
properties as we
have done in Listing 10-5.
CAReplicatorLayer
is an unusual and powerful subclass of
CALayer
. Its main job is to
replicate any sublayers that have been added to it. These sublayers can be replicated a
number of times based on the value of
the
-instanceCount
property. In addi-
tion to replicating its sublayers,
CAReplicatorLayer
will shift their colors
and transform the layers based on values
stored in the following instance proper-
ties:
.
instanceTransform
.
instanceColor
.
instanceRedOffset
.
instanceGreenOffset
.
instanceBlueOffset
.
instanceAlphaOffset
One use for
CAReplicatorLayer
is to
mimic the image reflections similar to
what you see in CoverFlow. You can
create a
UIView
that automatically
creates a reflection of its subviews (and
sublayers). The example we build is
shown in Figure 10-6.
FIGURE 10-6
A Reflection Layer Generated
with the CAReplicatorLayer
Building the UIView
You can begin this project by selecting the basic Window iPhone template in Xcode. Add
a
UIView
subclass to this template, called
ReplicatorView
. The entire purpose for