• 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: CA crossfade
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CA crossfade


  • Subject: Re: CA crossfade
  • From: Fritz Anderson <email@hidden>
  • Date: Sun, 15 Jul 2012 16:27:56 -0500

I'm an adventurer, so I tried this:

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

CABasicAnimation *	crossfade;
crossfade = [CABasicAnimation animationWithKeyPath: @"contents"];
crossfade.duration = 2.0;
crossfade.removedOnCompletion = YES;
[self.backgroundLayer addAnimation: crossfade forKey: nil];
=======

This works as I expect: The contents of the layer transition smoothly, without flicker.

	— F


On 15 Jul 2012, at 4:08 PM, Fritz Anderson wrote:

> 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 (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: 
 >CA crossfade (From: Fritz Anderson <email@hidden>)

  • Prev by Date: CA crossfade
  • Next by Date: NSAttributedString location for drawing, glyph location and baseline
  • Previous by thread: CA crossfade
  • Next by thread: NSAttributedString location for drawing, glyph location and baseline
  • Index(es):
    • Date
    • Thread