Graphics Reference
In-Depth Information
recycled ++;
[ self . recyclePool removeObject :layer];
}
else
{
//otherwise create a new one
layer = [CALayer layer ];
layer.frame = CGRectMake ( 0 , 0 , SIZE , SIZE );
}
//set position
layer.position = CGPointMake (x* SPACING , y* SPACING );
layer.zPosition = -z* SPACING ;
//set background color
layer.backgroundColor =
[UIColor colorWithWhite : 1 -z*( 1.0 / DEPTH ) alpha : 1 ].CGColor;
//attach to scroll view
[visibleLayers addObject :layer];
}
}
}
[CATransaction commit ];
//update layers
self . scrollView .layer.sublayers = visibleLayers;
//log
NSLog ( @"displayed: %i/%i recycled: %i" ,
[visibleLayers count ], DEPTH * HEIGHT * WIDTH , recycled);
}
@end
In this case, we only have one type of layer object, but UIKit sometimes uses an identifier
string to distinguish between multiple recyclable object types stored in separate pools.
You might have noticed that we're now using a CATransaction to suppress animation
when setting the layer properties. This wasn't needed before because we were only ever
setting properties on our layers once, prior to attaching them to the display. But now that
the layers are being recycled, it has become necessary to disable the implicit animation that
would normally occur when a visible layer's properties are modified.
Search WWH ::




Custom Search