Graphics Reference
In-Depth Information
14.
In the
MainMenu.xib
, Control-click on AppDelegate and drag the connection to the
Window object. Select window in the ensuing context menu.
15.
Save the xib file and return to Xcode.
The project is now set up. In the preceding steps, we created an application delegate that
we use to provide control to our layer, window, and view.
Add the Animation Layer to the Root Layer
To add a layer that we will be animating, do the following:
1.
Open
AppDelegate.h
and add a
CALayer
instance variable:
@interface
AppDelegate :
NSObject
{
IBOutlet
NSWindow *window;
CALayer
*layer;
}
2.
Open
AppDelegate.m
and add the layer initialization code in
-awakeFromNib
:
@implementation
AppDelegate
- (
void
)awakeFromNib;
{
[[window
contentView
] setWantsLayer:
YES
];
layer = [
CALayer layer
];
[layer setBounds:CGRectMake(0.0, 0.0, 100.0, 100.0)];
// Center the animation layer
[layer
setPosition
:
CGPointMake
([[window
contentView
]
frame
].
size.width
/2,
[[window
contentView
]
frame
].
size
.
height
/2)];
CGColorRef
color =
CGColorCreateGenericRGB
(0.4, 0.3, 0.2, 1);
[layer
setBackgroundColor
:color];
CFRelease
(color);
[layer
setOpacity
:0.75];
[layer
setBorderWidth
:5.0f];
[[[window
contentView
]
layer
]
addSublayer
:layer];
}
@end