iOS 7.1 Slide To Unlock Text Animation

前端 未结 8 1689
傲寒
傲寒 2021-02-05 11:56

I\'m not sure if this has been asked before, but I\'m having a hard time finding it. Perhaps I\'m not using the right search terms, so if an answer already exists, if someone c

相关标签:
8条回答
  • 2021-02-05 12:20

    You can animate label text and use custom slider for it, I hope it helps you:

    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.15f] CGColor];
    maskLayer.contents = (id)[[UIImage imageNamed:@"Mask.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(myLabel.frame.size.width * -1, 0.0f,   myLabel.frame.size.width * 2, myLabel.frame.size.height);
    // Animate the mask layer's horizontal position
    CABasicAnimation *maskAnim = [CABasicAnimation animationWithKeyPath:@"position.x"];
    maskAnim.byValue = [NSNumber numberWithFloat:myLabel.frame.size.width];
    maskAnim.repeatCount = 1e100f;
    maskAnim.duration = 1.5f;
    [maskLayer addAnimation:maskAnim forKey:@"slideAnim"];
    myLabel.layer.mask = maskLayer;
    
    0 讨论(0)
  • 2021-02-05 12:21

    You should be able to use the mask property of CALayer to create a cutout of the contents of another layer.

    Set the mask to contain your text (maybe a CATextLayer can work here). This is what Shimmer says it uses.

    0 讨论(0)
提交回复
热议问题