博客> 歌词滚动
歌词滚动
2018-07-20 09:46 评论:0 阅读:672 深山野猪
ios
UILabel *backLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 300, 40)];
backLabel.textColor = [UIColor redColor];
backLabel.font = [UIFont systemFontOfSize:30];
backLabel.text = @"原来你也在这里";
backLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:backLabel];

UILabel *foreLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 300, 40)];
foreLabel.textColor = [UIColor whiteColor];
foreLabel.text = @"原来你也在这里";
foreLabel.font = [UIFont systemFontOfSize:30];
foreLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:foreLabel];

CAGradientLayer *layer = [CAGradientLayer layer];
layer.frame = foreLabel.bounds;
layer.colors = @[(id)[UIColor clearColor],(id)[UIColor redColor].CGColor,(id)[UIColor blackColor].CGColor,(id)[UIColor clearColor].CGColor];
layer.locations = @[@(0.01),@(0.1),@(0.9),@(0.99)];
    layer.startPoint = CGPointMake(0, 0);
    layer.endPoint = CGPointMake(1, 0);
foreLabel.layer.mask = layer;

CABasicAnimation *basicAnimation = [CABasicAnimation animation];
basicAnimation.keyPath = @"transform.translation.x";
basicAnimation.fromValue = @(0);
basicAnimation.toValue = @(foreLabel.bounds.size.width);
basicAnimation.duration = 2;
basicAnimation.repeatCount = LONG_MAX;
basicAnimation.removedOnCompletion = NO;
basicAnimation.fillMode = kCAFillModeForwards;
[foreLabel.layer.mask addAnimation:basicAnimation forKey:nil];
收藏
0
sina weixin mail 回到顶部