btn 跑马灯效果

btn.titleLabel.numberOfLines=0;
[btn.titleLabel sizeToFit];
CAShapeLayer* maskLayer = [CAShapeLayer layer];
maskLayer.path = [UIBezierPath bezierPathWithRect:btn.titleLabel.bounds].CGPath;
btn.titleLabel.layer.mask = maskLayer;
CAKeyframeAnimation* keyFrame = [CAKeyframeAnimation animation];
keyFrame.keyPath = @"transform.translation.x";
keyFrame.values = @[@(0), @(-30), @(0)];
keyFrame.repeatCount = NSIntegerMax;
keyFrame.duration = 0.6 * btn.titleLabel.text.length;
keyFrame.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], [CAMediaTimingFunction functionWithControlPoints:0 :0 :0.5 :0.5]];
// keyFrame.delegate = self;
[btn.titleLabel.layer addAnimation:keyFrame forKey:nil];

你可能感兴趣的:(btn 跑马灯效果)