CATransaction block volume

I saw some code that removes a given layer from it with a superlayer by doing the following:

void RemoveImmediately(CALayer *layer) {
    [CATransaction flush];
    [CATransaction begin];
    [CATransaction setValue:(id)kCFBooleanTrue
                     forKey:kCATransactionDisableActions];
    [layer removeFromSuperlayer];
    [CATransaction commit];
}  

I wrote a method that changes the position of a given layer in an animated way using CAKeyframeAnimation, which looks like this:

- (void)animateMovingObject:(NXUIObject*)obj
           fromPosition:(CGPoint)startPosition
             toPosition:(CGPoint)endPosition
               duration:(NSTimeInterval)duration {    

    CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    pathAnimation.calculationMode = kCAAnimationPaced;
    pathAnimation.duration = duration;

    CGMutablePathRef curvedPath = CGPathCreateMutable();
    CGPathMoveToPoint(curvedPath, NULL, startPosition.x, startPosition.y);
    CGPathAddCurveToPoint(curvedPath, NULL, 
                      startPosition.x, endPosition.y, 
                      startPosition.x, endPosition.y,
                      endPosition.x, endPosition.y);
    pathAnimation.path = curvedPath;
    [obj addAnimation:pathAnimation forKey:@"pathAnimation"];
    CGPathRelease(curvedPath);
}

To be honest, everything is in order. Now suppose I have a โ€œmaster layerโ€ in my application that has 3 sublayers. I want the first two subwords to be moved to another place, and the last to be deleted. So I did the following:

CALayer obj1 = ... // set up layer and add as sublayer
[self.masterLayer addSublayer:obj1];
[self animateMovingObject:obj1
             fromPosition:CGPointMake(0.0, 0.0)
               toPosition:CGPointMake(100.0, 100.0)
                 duration:2.0];

CALayer obj2 = ... // set up layer and add as sublayer
[self.masterLayer addSublayer:obj2];
[self animateMovingObject:obj2
             fromPosition:CGPointMake(0.0, 0.0)
               toPosition:CGPointMake(150.0, 100.0)
                 duration:2.0];

CALayer obj3 = ... // set up layer and add as sublayer
[self.masterLayer addSublayer:obj3];
// ...
RemoveImmediately(obj3);      // This removes the two previous animations too
//[obj3 removeFromSuperlayer];  // This just removes obj3, the previous animations works

, RemoveImmediately(), obj3 , , . , obj3, removeFromSuperlayer, . , CATransaction , , CAKeyframeAnimation.

?

.

0
1

CAT- [CATransaction begin] [CATransaction commit].

, [CATransaction flush] . Apple , , , .

, - , , - . , , , . , ( ..).

+2

All Articles