Graphics Reference
In-Depth Information
LISTING 12-2
Continued
descriptionLabel
= [[UILabel alloc] initWithFrame:CGRectZero];
[
descriptionLabel
setNumberOfLines:0];
[
descriptionLabel
setFont:[UIFont systemFontOfSize:6.0f]];
[
descriptionLabel
setBackgroundColor:[UIColor whiteColor]];
[contentView addSubview:
descriptionLabel
];
[
descriptionLabel
release];
[[NSNotificationCenter defaultCenter] addObserver:
self
selector:
@selector
(
imageUpdated
:)
name:
kImageDownloadComplete
object:
nil
];
return self
;
}
Core Animation has a great feature that enables you to display and quickly view highly
detailed images within your application.
CATiledLayer
is designed to display large images
without having to load the entire image into memory and cause performance issues.
To demonstrate the usefulness of
CATiledLayer
, open the TiledLayers
sample application that accompanies
this chapter. In this application, a very
large image (6064 × 4128) is loaded and
the ability to zoom in and out of it is
enabled. Normally, large images are
loaded fully into memory before they
are displayed, and that can cause a huge
performance issue. However, by loading
the image into a
CATiledLayer
, Core Animation handles all of the memory issues for us.
Core Animation loads in only parts of the image as needed rather than pulling in the
entire file. All you need to do to configure the
CATiledLayer
is to give it the levels of
detail used to determine zoom levels, along with the tile size.
NOTE
CATiledLayer
solves a number of problems
that occur in both desktop development and
iPhone development. Specifically it enables
you to handle large images, multiresolution
data, and handles on-demand loading auto-
matically.
In the TiledLayers application, a single
CATiledLayer
is initialized in the main window
and is assigned an
NSSegmentedControl
(via Interface Builder) to manage the levels of
zoom. The resulting window is shown in Figure 12-4.