iPhone CALayer-animation

Ich bin eine Linie zeichnen animation, verbinden Sie 2 Punkte mit einer Linie. Das ist mein code:

-(void) drawObject{     
    rootLayer   = [CALayer layer];
    rootLayer.frame = self.view.bounds;
    [self.view.layer addSublayer:rootLayer];

    lineStartPath = CGPathCreateMutable();
    CGPathMoveToPoint(lineStartPath, nil, 160, 50);
    CGPathAddLineToPoint(lineStartPath, nil, 160, 50);
    CGPathCloseSubpath(lineStartPath);

    lineEndPath = CGPathCreateMutable();
    CGPathMoveToPoint(lineEndPath, nil, 160, 50);
    CGPathAddLineToPoint(lineEndPath, nil, 160, 300);
    CGPathCloseSubpath(lineEndPath);

    shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = lineStartPath;
    UIColor *strokeColor = [UIColor colorWithHue:0.557 saturation:0.55 brightness:0.96 alpha:1.0];
    shapeLayer.strokeColor = strokeColor.CGColor;
    shapeLayer.lineWidth = 3.0;

    [rootLayer addSublayer:shapeLayer];

    [self performSelector:@selector(startAnimation) withObject:nil afterDelay:1.0];
}

-(void) startAnimation{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
    animation.duration = 0.5;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    animation.fromValue = (id)lineStartPath;
    animation.toValue = (id)lineEndPath;
    [shapeLayer addAnimation:animation forKey:@"animatePath"];
}

Der schwache Punkt ist, nachdem die animation beendet ist, wird die Linie verschwindet. Ich möchte, dass nach meiner Linie ist gezogen zwischen denjenigen, die 2 Punkte, die id nicht verschwinden. Mir einen Tipp geben bitte.

InformationsquelleAutor Oleg Danu | 2011-02-21
Schreibe einen Kommentar