Graphics Reference
In-Depth Information
After applying the transform, shift the
colors (red, green, blue, and the alpha
value) of the duplicated layers closer to
black. The reason for this color shift is
because the background of the window
to which the view is added is black. This
gives the layer a nice glossy reflection.
NOTE
In a production application this transform
would probably need to be calculated at a
later point in the application's execution.
All of these “instance” properties are used to instruct CAReplicatorLayer what to do with
the layers it is generating. The initial layer remains untouched, but each subsequent layer
from the first (based on the instanceCount property) will have transform and offset
values applied. In addition, if the layer is duplicated more than once, each subsequent
layer will receive the transform of the previous copy and an increase of its own. In this
project, if we had more than one copy, we would see them fading closer and closer to
black, and they would alternate vertically while being moved further and further down
the screen.
Utilizing the ReplicatorView
Finally, we need to initialize an instance of the ReplicatorView , add it to the window,
and then give it a subview to replicate. This is all accomplished in the AppDelegate , as
shown in Listing 10-8.
LISTING 10-8 Adding the ReplicatorView to the Window
- ( void )applicationDidFinishLaunching:( UIApplication *)application
{
CGRect frame = [[ UIScreen mainScreen ] applicationFrame ];
UIView *replicatorView = nil ;
replicatorView = [[ReplicatorView alloc ] initWithFrame :frame];
[window addSubview :replicatorView];
UIImage *lacey = [ UIImage imageNamed : @”Lacey1.png” ];
UIImageView *imageView = [[ UIImageView alloc ] initWithImage :lacey];
[imageView setFrame : CGRectMake (10, 10, 300, 220)];
[imageView setContentMode : UIViewContentModeScaleAspectFit ];
[replicatorView addSubview :imageView];
[window setBackgroundColor :[ UIColor blackColor ]];
[window makeKeyAndVisible ];
[imageView release ], imageView = nil ;
[replicatorView release ], replicatorView = nil ;
}
 
Search WWH ::




Custom Search