Re: Can an image be "rejected" by CALayer?
Re: Can an image be "rejected" by CALayer?
- Subject: Re: Can an image be "rejected" by CALayer?
- From: Gabriel Zachmann <email@hidden>
- Date: Mon, 11 Apr 2011 21:40:21 +0200
>
>
> Show all the code by which the layer is configured and put into the interface if you want a more educated response. m.
>
I'll try, it's a bit scattered throughout my program.
(I was a bit hesitant to flood my original post with potentially unwanted code ...)
Here goes:
CGImageRef imageRef = CGImageSourceCreateImageAtIndex( sourceRef, 0, NULL );
CALayer * newlayer;
NSSize startsize = drawRect_.size;
startsize.width *= MinimalImageSizeDisplayed;
startsize.height *= MinimalImageSizeDisplayed;
NSSize endsize = startsize;
endsize.width *= 1.5;
endsize.height *= 1.5;
newlayer = [self makeImageLayer: imageRef fromSize: startsize toSize: endsize withOrientation: img_orientation];
// swap the old and the new layer
[CATransaction begin];
// causes cross-dissolve animation
[CATransaction setValue: [NSNumber numberWithFloat: fading_duration] forKey: kCATransactionAnimationDuration ];
[mainLayer_ replaceSublayer: currentLayer_ with: newlayer];
currentLayer_ = newlayer;
[CATransaction commit];
- (CALayer *) makeImageLayer: (CGImageRef) img fromSize: (NSSize) startsize toSize: (NSSize) endsize withOrientation: (int) orientation
{
CALayer * imgLayer = [self makeImageLayer: img withOrientation: orientation];
// create animation for growing/shrinking
CABasicAnimation * anim = [CABasicAnimation animationWithKeyPath: @"bounds.size"];
anim.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut];
anim.duration = durationPerCycle_;
anim.autoreverses = YES;
anim.repeatCount = 1e100; // = forever
if ( orientation < 1 || orientation > 8 )
orientation = 1;
if ( orientation <= 4 )
{
anim.fromValue = [NSValue valueWithSize: startsize];
anim.toValue = [NSValue valueWithSize: endsize];
}
else
{
// swap width & height, because the image's orientation is a transposition or rotation
anim.fromValue = [NSValue valueWithSize: NSMakeSize(startsize.height, startsize.width) ];
anim.toValue = [NSValue valueWithSize: NSMakeSize(endsize.height, endsize.width) ];
}
[imgLayer addAnimation: anim forKey: nil];
return imgLayer;
}
As I said, some images just won't get displayed under 10.5, but the same images work fine under 10.6.
Best regards,
Gabriel.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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