CALayer glitch: move one sublayer, add/remove another
CALayer glitch: move one sublayer, add/remove another
- Subject: CALayer glitch: move one sublayer, add/remove another
- From: Dave Hayden <email@hidden>
- Date: Wed, 16 Jul 2008 11:35:09 -0700
Just wanted to see if this is expected behavior, and if there's a
workaround. When I add or remove one sublayer and change another's
position in the same transaction, the moved layer leaves a "ghost"
image that fades away at the start position. If I wrap the two actions
in CATransaction begin/commit, it works as expected (no ghost image)
if I do the position change first, then the add/remove. If I do the
add/remove first, I get the ghost image.
I've tried delaying all my addSublayer/removeFromSuperlayer calls in
my app until after the position changes, but no luck--there's a lot
more stuff going on there, I'm sure. If I disable actions in the add/
remove transaction, it doesn't ghost the position changes. (But I do
want the add/remove animation..)
Any idears before I send this to radar?
-Dave
Panic, Inc.
@interface TestView : NSView
{
CALayer* layerOne;
CALayer* layerTwo;
}
@end
@implementation TestView
- (void)awakeFromNib
{
[self setWantsLayer:YES];
layerOne = [[CALayer layer] retain];
layerOne.backgroundColor = CGColorCreateGenericRGB(1.0, 0.0, 0.0, 1.0);
layerOne.bounds = CGRectMake(0, 0, 100, 100);
layerOne.position = CGPointMake(200, 200);
[[self layer] addSublayer:layerOne];
layerTwo = [[CALayer layer] retain];
layerTwo.backgroundColor = CGColorCreateGenericRGB(0.0, 0.0, 1.0, 1.0);
layerTwo.bounds = CGRectMake(0, 0, 100, 100);
layerTwo.position = CGPointMake(300, 200);
[[self layer] addSublayer:layerTwo];
}
- (void)mouseDown:(NSEvent*)event
{
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithInt:2]
forKey:kCATransactionAnimationDuration];
if ( [layerTwo superlayer] != nil )
[layerTwo removeFromSuperlayer];
else
[[self layer] addSublayer:layerTwo];
[CATransaction commit];
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithInt:2]
forKey:kCATransactionAnimationDuration];
layerOne.position = CGPointMake(rand() % (int)NSWidth([self frame]),
rand() % (int)NSHeight([self frame]));
[CATransaction commit];
}
@end
_______________________________________________
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