ios - 需要有关滑动解锁的帮助,如动画

标签 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 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。但是,您发布的代码是固定动画,而不是响应滑动手势的代码。

关于ios - 需要有关滑动解锁的帮助,如动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36220387/

相关文章:

iphone - 使用 segue 传回数据时卡住

android - 如何处理 Phonegap iOS/Android 项目并对其进行正确的版本控制?

ios - 如何放大和缩小 MKMapView 中的 MKCircle 同一个按钮单击 ios?

ios - RKMappingresult 在带有 restkit 的 64 位 iPhone 中返回不同的结果

objective-c - 无法选择注释?

ios - 以编程方式设置 RGB

ios - 菜单中的动画,如愤怒的小鸟或小翅膀

iOS 时间 View

ios - TableView 中的重复行

ios - UILabel 在 iOS7 中有一个奇怪的灰色顶线/边框,我该如何删除它?