Graphics Reference
In-Depth Information
FIGURE 12-4
Tiled Layer Application
When the interface has been designed, construct the CATiledLayer in the -awakeFromNib
method of the Application Delegate, as shown in Listing 12-3.
LISTING 12-3
-awakeFromNib
- ( void )awakeFromNib
{
NSString *imagePath = [[ NSBundle mainBundle ] pathForResource : @”BigSpaceImage”
ofType : @”png” ];
NSData *data = [ NSData dataWithContentsOfFile :imagePath];
image = [[ CIImage imageWithData :data] retain ];
tiledLayer = [ CATiledLayer layer ];
[ tiledLayer setBounds : CGRectMake (0, 0, 6064, 4128)];
float midX = NSMidX ( NSRectFromCGRect ([[ view layer ] frame ]));
float midY = NSMidY ( NSRectFromCGRect ([[ view layer ] frame ]));
[ tiledLayer setPosition : CGPointMake (midX, midY)];
[ tiledLayer setLevelsOfDetail :4]; //number of levels
[ tiledLayer setTileSize : CGSizeMake (256, 256)];
[ tiledLayer setDelegate : self ];
[[ view layer ] addSublayer : tiledLayer ];
}
When the app has the path to the image, the path is loaded into a CIImage call and
stored for later use. CATiledLayer is initialized and applied to the bounds of the image
that will be displayed. Next, the image is positioned within the root layer by setting its
position and configuring the levels of available zoom. The last step is to assign the
 
Search WWH ::




Custom Search