Graphics Reference
In-Depth Information
We then add the layer to our view. Then we add each of our individual
CALayers
with
their
contents
and
contentsRect
fields set.
The code to implement this is fairly simple. You set the contents of each
CALayer
to the
contents of the movie layer, as shown in the following code:
[layer
setContents
:[movieLayer
contents
]];
Then you set the
contentsRect
to display only the portion of the movie layer that you
want to show in that particular layer. You set the
contentsRect
field like this:
[layer
setContentsRect
:
CGRectMake
(0.25f, 0.25f, 0.25f, 0.25f)];
As you can recall from Chapter 2, this causes the contents of the
CALayer
to display one-
quarter of the width and height starting one-quarter of the distance from the bottom-left
corner of the movie layer.
Interestingly, this trick does not work with the
QTCaptureLayer
that we cover in the next
section.
QTCaptureLayer
provides a means for displaying content from video devices connected to
your computer. These devices include your iSight camera or a digital video camera
connected via FireWire. To capture the video, you have to set up a
QTCaptureSession
,
which does two things:
.
It provides an interface to receive frames from the capture device.
.
It enables you to save the images to a movie file and hand that session off to
QTCaptureLayer
.
The most complicated aspect of capturing video to display in the
QTCaptureLayer
is not
in the layer at all. Rather, the
QTCaptureSession
object has the majority of the setup. This
setup requires several steps that include obtaining a device, opening the device, adding
the device to the capture session, and creating a video output object to add raw frames to
the capture session.
It will be helpful if you open the sample project called Photo Capture and build the
project. When you run it, you see a screen like the one in Figure 7-7.