This might be my lack of understanding of the call stack when using Core Animation, but something confuses me a little about who/what is calling drawInContext.
Lets say I have
@interface PlayerLayer : CALayer
{
int Foo;
}
and I initialize Foo in init to be something like
-(void) init
{
if( self = [super init] )
{
Foo = 123;
}
}
When drawInContext is first called, I print out Foo
- (void)drawInContext:(CGContextRef)ctx
{
NSLog(@"Foo: %d", Foo)
}
The first time 'drawInContext' is called when the layer is added and setNeedsDisplay triggers the call, Foo = 123 as it should.
I have an animation set up for a property key called "Bar" for example, in which 'needsDisplayForKey' returns YES for the key "Bar". When this animation triggers 'drawInContext' all the instance variables are set to 0, and as such Foo prints out as 0. Also the 'self' pointer value has changed.
Can anyone shine any light on why drawInContext seems to be called from some other magical location, and not from within the instance of the layer that I expect it to be?
It means that any state variables that I have stored in the instance cant be used :-(