10.7 SDK, 10.7 target. The content view of the window is layer-hosting, 
containing only a CALayer.

I'm trying to crossfade the contents image of the CALayer from Image A (the 
existing contents) to Image B (the new contents). Surely this is simple. I'm 
thrashing.

Here is an excerpt from my controller object's set-image method. I've seen the 
following code (more or less) in responses on the Web, and it has always met 
with apparent satisfaction, but it does not work as I intend: Image A is 
instantly replaced by Image B, then the crossfade from A to B runs. Image B 
remains.

=====
//  Initialize nsImage with the new contents.
CABasicAnimation *      crossfade;
crossfade = [CABasicAnimation animationWithKeyPath: @"contents"];

crossfade.duration = 0.75;
crossfade.removedOnCompletion = YES;
crossfade.fromValue = self.backgroundLayer.contents;
crossfade.toValue = nsImage;
[self.backgroundLayer addAnimation: crossfade forKey: nil];

self.backgroundLayer.contents = nsImage;
=====

Commenting-out the assignments to .fromValue and .toValue yields the same 
effect.

Okay, try this: add

crossfade.delegate = self;

before the addAnimation:, and delete

self.backgroundLayer.contents = nsImage;

Add the delegate method:

- (void) animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    NSImage *   newImage = [(CABasicAnimation *)anim toValue];
    self.backgroundLayer.contents = newImage;
}

Printing the nsImage pointer in the set-image method and newImage in the 
animationDidStop: method shows that the two pointers are equal.

In this case, the animation runs from Image A to Image B, then jumps to Image 
A, then jumps to Image B.

In all cases, self.backgroundLayer.actions is nil.

I'm thrashing at a task that ought to be simple and obvious. What am I missing?

        — F


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to