需要有关幻灯片解锁的帮助,如动画

时间:2016-03-25 12:56:35

标签: ios objective-c uilabel core-animation cabasicanimation

我正在使用此代码创建幻灯片以解锁动画,但我无法通过right to left制作动画。

如何从右侧开始,从左侧开始动画?

-(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;
}

1 个答案:

答案 0 :(得分:0)

您应该能够简单地使用负值byValue。但是,您发布的代码是一个预制动画,而不是一个响应幻灯片动画的动画。