【问题标题】:Need assistance regarding slide to unlock like animation需要有关幻灯片的帮助才能像动画一样解锁
【发布时间】:2016-03-25 12:56:35
【问题描述】:

我正在使用此代码创建幻灯片以像动画一样解锁,但我无法通过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;
}

【问题讨论】:

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


    【解决方案1】:

    您应该能够简单地使用负值 byValue。但是,您发布的代码是固定动画,而不是响应滑动手势的代码。

    【讨论】:

    • 我尝试了负值,但它给出了奇怪的动画行为。我觉得重力在起作用,但是如何让它从右到左动画。
    • 我之前没有尝试过使用 contentsGravity。摆脱 byValue 并设置 fromValue 和 toValue 怎么样?
    • 请您更新您的最后一条评论作为答案,以便我可以将其连根拔起并勾选正确答案。
    猜你喜欢
    • 2015-07-10
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 2019-06-30
    • 2010-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多