Graphics Reference
In-Depth Information
//calculate clipping bounds
CGRect bounds = self . scrollView .bounds;
bounds.origin = self . scrollView .contentOffset;
bounds = CGRectInset (bounds, - SIZE / 2 , - SIZE / 2 );
//add existing layers to pool
[ self . recyclePool addObjectsFromArray : self . scrollView .layer.sublayers];
//disable animation
[CATransaction begin ];
[CATransaction setDisableActions : YES ];
//create layers
NSInteger recycled = 0 ;
NSMutableArray *visibleLayers = [NSMutableArray array ];
for ( int z = DEPTH - 1 ; z >= 0 ; z--)
{
//increase bounds size to compensate for perspective
CGRect adjusted = bounds;
adjusted.size.width /= PERSPECTIVE (z* SPACING );
adjusted.size.height /= PERSPECTIVE (z* SPACING );
adjusted.origin.x -= (adjusted.size.width - bounds.size.width) / 2 ;
adjusted.origin.y -= (adjusted.size.height - bounds.size.height) / 2 ;
for ( int y = 0 ; y < HEIGHT ; y++)
{
//check if vertically outside visible rect
if (y* SPACING < adjusted.origin.y ||
y* SPACING >= adjusted.origin.y + adjusted.size.height)
{
continue ;
}
for ( int x = 0 ; x < WIDTH ; x++)
{
//check if horizontally outside visible rect
if (x* SPACING < adjusted.origin.x ||
x* SPACING >= adjusted.origin.x + adjusted.size.width)
{
continue ;
}
//recycle layer if available
CALayer *layer = [ self . recyclePool anyObject ];
if (layer)
{
Search WWH ::




Custom Search