我已经能够使用来自另一个堆栈溢出问题的代码(iPhone“滑动解锁”动画)以“滑动解锁”样式制作一些文本脉冲。此刻,面具从左向右移动。我想反转它,而不是让它从左到右脉动,而是从右到左脉动。
我摆弄了代码,试图弄清楚如何扭转它,但我所做的一切都没有让它正常工作!所有我认为会奏效的东西,都没有。
任何帮助将不胜感激。
self.view.layer.backgroundColor = [[UIColor blackColor] CGColor];
CGFloat textWidth = 320;
CGFloat textHeight = 76;
CALayer *textLayer = [CALayer layer];
textLayer.contents = (id)[self.MYSLIDEIMAGE.image CGImage];
textLayer.frame = CGRectMake(-69.0f, 350.0f, textWidth, textHeight);
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.1f] 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(-textWidth +50, 0.0f, textWidth * 2, textHeight);
// Animate the mask layer's horizontal position
CABasicAnimation *maskAnim = [CABasicAnimation animationWithKeyPath:@"position.x"];
maskAnim.byValue = [NSNumber numberWithFloat:textWidth -50];
maskAnim.repeatCount = HUGE_VALF;
maskAnim.duration = 2.8f;
[maskLayer addAnimation:maskAnim forKey:@"slideAnim"];
textLayer.mask = maskLayer;
[self.view.layer addSublayer:textLayer];