Graphics Reference
In-Depth Information
LISTING 5-6
Continued
[layer setBackgroundColor:color];
[layer setCornerRadius:5.0f];
color = CGColorCreateGenericRGB (0.0f, 1.0f, 0.0f, 1.0f);
[layer setBorderColor:color];
[layer setBorderWidth:2.0f];
[ layer setBounds : CGRectMake (0, 0, 100, 100)];
[layer setPosition:CGPointMake(55, 55)];
[rootLayer addSublayer : layer ];
}
The -applicationDidFinsihLaunching: method grabs a reference to the contentView and
adds a CALayer to it before turning on layer backing. The rootLayer 's background color is
also black.
Next, create the layer we are going to manipulate and set its color to gray with a green,
2-pixel border and a 5-pixel corner radius. Unlike Listing 5-1, this layer will be 100 × 100
pixels and positioned in the lower-left corner of the contentView .
There's also one additional change to make in Interface Builder. Add a square NSButton
to the contentView , make it transparent, and resize the button to the same dimensions as
the window. This enables the user to click anywhere within the window and trigger the
action, which we get to next.
Bind the large button's action to the AppDelegate and its -(IBAction)action:(id)sender
method that we are about to declare.
When the user clicks on the window, we want to take the workingLayer and move it to
the upper-right corner. While doing that, we want to both rotate the layer 180 degrees
and scale it down to one-tenth its current size. The first possible solution to this problem
can be found in Listing 5-7.
LISTING 5-7
-action:
- ( IBAction )action:( id )sender;
{
NSRect frame = [[[ self window] contentView] frame];
float x = frame. origin . x + frame. size . width - 30;
float y = frame. origin . y + frame. size . height - 30;
CATransform3D rotate;
CATransform3D scale;
 
Search WWH ::




Custom Search