• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting started with Core Animation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting started with Core Animation


  • Subject: Re: Getting started with Core Animation
  • From: Matt Long <email@hidden>
  • Date: Mon, 2 Jun 2008 22:06:41 -0600

Hey Graham. I wrote a blog post not too long ago that demonstrates adding layers to a root layer. You can see it here: http://www.cimgf.com/2008/03/15/core-animation-tutorial-dashboard-effect/

I think you want to get the root content layer and then call insertSublayer or addSublayer to it. Here's what I do in the awakeFromNib in that blog post:

-(void)awakeFromNib;
{
[[window contentView] setWantsLayer:YES];
[window setFrame:[[NSScreen mainScreen] frame] display:NO animate:NO];


	NSRect contentFrame = [[window contentView] frame];
    CALayer *root = [[window contentView] layer];

    // mainLayer is the layer that gets scaled. All of its sublayers
    // are automatically scaled with it.
    mainLayer = [CALayer layer];
    mainLayer.frame = NSRectToCGRect(contentFrame);

// Make the background color to be a dark gray with a 50% alpha similar to
// the real Dashbaord.
mainLayer.backgroundColor = CGColorCreateGenericRGB(0.10, 0.10, 0.10, 0.50);
[root insertSublayer:mainLayer above:0];


    // Add a new layer to the mainlayer.
    [self addNewLayer:nil];

	scaleUp = YES;
}

You can get my demo project from here: http://www.cimgf.com/wp-content/uploads/2008/03/dashboardeffect.zip

HTH

-Matt



On Jun 2, 2008, at 9:51 PM, Graham Cox wrote:

Hi all,

I'm looking at Core Animation for the first time. Having a bit of trouble getting started with the simplest set-up I can imagine.

Goal - to add a single CALayer in my view so I can see it. Then, try some simple animations. I've tried a few different things but I just can't see any visible trace of my layer. Here's the code, part of my custom view (actually, almost all of it):

- (id)	initWithFrame:(NSRect)frame
{
   self = [super initWithFrame:frame];
   if (self)
	{
		CALayer* rootLayer = [CALayer layer];

		theLayer = [CALayer layer];

		CGRect 		frame = {10,10,110,150};
		CGColorRef	bk = CGColorCreateGenericRGB( 0.5, 0.5, 0, 1.0 );

		[theLayer setCornerRadius:10.0];
		[theLayer setBorderWidth:4.0];
		[theLayer setFrame:frame];
		[theLayer setBackgroundColor:bk];

		[rootLayer addSublayer:theLayer];

		[self setLayer:rootLayer];
		[self setWantsLayer:YES];

		CGColorRelease( bk );
   }
   return self;
}


n.b. 'theLayer' is an ivar.

Initially I didn't have a separate rootLayer, but looking at some sample code it seems most code uses one. Even though there's no layer content set I should see the border and the background colour shouldn't I? What am I missing?

BTW, another things that's a little unclear - when the rootLayer is added to the view, does it adopt the view's frame? Or should I be setting this explicitly? Sample code appears to just let it use its defaults.


thanks for any insight,


Graham _______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Getting started with Core Animation (From: Graham Cox <email@hidden>)

  • Prev by Date: A little extra cash...
  • Next by Date: Hillegass book memory question
  • Previous by thread: Getting started with Core Animation
  • Next by thread: A little extra cash...
  • Index(es):
    • Date
    • Thread