Graphics Reference
In-Depth Information
Figure 6.10
The
ReflectionView
automatically creates a reflection at runtime
A more complete, open source implementation of the
ReflectionView
class, complete
with an adjustable gradient fade effect (implemented using
CAGradientLayer
and layer
masking), can be found at
https://github.com/nicklockwood/ReflectionView
.
For an untransformed layer, the size of a layer's
bounds
will match the size of its
frame
.
The
frame
is calculated automatically from the
bounds
, so changing either property will
update the other.
But what if you want to display only a small part of a larger layer? For example, you might
have a large image that you want the user to be able to scroll around, or a long list of data
or text. In a typical iOS application, you might use a
UITableView
or
UIScrollView
,
for this, but what's the equivalent when working with standalone layers?
In Chapter 2, we explored the use of the layer
contentsRect
property, which is a good
solution for displaying only a small part of a larger image in a layer. It's not a very good
solution if your layer contains sublayers, though, as you would need to manually recalculate
and update all the sublayer positions every time you wanted to “scroll” the visible area.
That's where
CAScrollLayer
comes in.
CAScrollLayer
has a
-scrollToPoint:
method that automatically adjusts the origin of the
bounds
so that
the layer contents appear to scroll. Note, however, that that is
all
it does. As discussed
earlier, Core Animation does not handle user input, so
CAScrollLayer
is not
responsible for turning touch events into a scrolling action, nor does it render scrollbars or