Ios 需要有关幻灯片的帮助才能像动画一样解锁吗

Ios 需要有关幻灯片的帮助才能像动画一样解锁吗,ios,objective-c,uilabel,core-animation,cabasicanimation,Ios,Objective C,Uilabel,Core Animation,Cabasicanimation,我正在使用此代码创建幻灯片以像动画一样解锁,但我无法使其从右向左设置动画 如何使其从右开始并向左设置动画 -(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 th

我正在使用此代码创建幻灯片以像动画一样解锁,但我无法使其从
右向左
设置动画

如何使其从右开始并向左设置动画

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

您应该能够简单地使用负的byValue。但是,您发布的代码是一个罐装动画,而不是一个对幻灯片手势做出响应的动画。

我尝试了负值,但它给出了奇怪的动画行为。我认为重力在扮演一些角色,但如何使它从右到左充满活力。我以前从未尝试过使用contentsGravity。如何摆脱byValue,改为设置fromValue和toValue?请您更新您的最后一条评论作为答案,这样我就可以将其删除并勾选为正确答案。