2016-03-25 11 views
2

Ich verwende diesen Code, um die Folie zum Entsperren wie Animation zu erstellen, aber ich kann es nicht animieren von right to left.Brauchen Sie Unterstützung in Bezug auf Folie zum Entsperren wie Animation

Wie kann ich es von rechts beginnen und nach links animieren?

-(void)slideToCancel { 
    CALayer *maskLayer = [CALayer layer]; 
    // Mask image ends with 0.15 opacity on both sides. Set the background color of the   layer 
    // to the same value so the layer can extend the mask image. 
    maskLayer.backgroundColor = [[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.50f] CGColor]; 
    maskLayer.contents = (id)[[UIImage imageNamed:@"slidetocancel.png"] CGImage]; 

    // Center the mask image on twice the width of the text layer, so it starts to the left 
    // of the text layer and moves to its right when we translate it by width. 
    maskLayer.contentsGravity = kCAGravityCenter; 
    maskLayer.frame = CGRectMake(_slideToCancelLbl.frame.size.width * -1, 0.0f, _slideToCancelLbl.frame.size.width * 2, _slideToCancelLbl.frame.size.height); 
    // Animate the mask layer's horizontal position 
    CABasicAnimation *maskAnim = [CABasicAnimation animationWithKeyPath:@"position.x"]; 
    maskAnim.byValue = [NSNumber numberWithFloat:_slideToCancelLbl.frame.size.width]; 
    maskAnim.repeatCount = 1e100f; 
    maskAnim.duration = 1.5f; 
    [maskLayer addAnimation:maskAnim forKey:@"slideAnim"]; 
    _slideToCancelLbl.layer.mask = maskLayer; 
} 

Antwort

0

Sie sollten einfach einen negativen byValue verwenden können. Der von Ihnen gepostete Code ist jedoch eine vordefinierte Animation, die nicht auf eine Foliengeste reagiert.

+0

Ich versuchte den negativen Wert, aber es gibt ungerade Animation Verhalten. Ich denke, die Schwerkraft spielt eine Rolle, aber wie man sie von rechts nach links animiert. –

+0

Ich habe nicht versucht, contentsGravity vorher zu verwenden. Wie wäre es, byValue loszuwerden und stattdessen fromValue und toValue zu setzen? –

+0

Bitte aktualisieren Sie Ihren letzten Kommentar als Antwort, damit ich ihn entwurzeln und als richtige Antwort abhaken kann. –