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 protected])

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

This email sent to [EMAIL PROTECTED]

Reply via email to