我正在尝试添加到CATextlayer中的一组动画;一个不透明度的动画,它使图层在几秒后消失,并且是一个“摇动”的动画,在这个动画中,我希望图层在它访问时稍微摇动一下。 不透明度动画效果很好;摇晃没有做任何事情 - 我希望我能解释一下原因。
这是我的图层和不透明度动画的代码,它可以正常工作:
CATextLayer *subtitle1Text = [[CATextLayer alloc] init];
[subtitle1Text setFont:@"Helvetica-Bold"];
[subtitle1Text setFontSize:25];
[subtitle1Text setFrame:CGRectMake(0, 0, self.screenSize.width, 100)];
[subtitle1Text setString: self.videoDescription1.text ];
[subtitle1Text setAlignmentMode:kCAAlignmentCenter];
[subtitle1Text setForegroundColor:[[UIColor whiteColor] CGColor]];
CABasicAnimation *animation1 =[CABasicAnimation animationWithKeyPath:@"opacity"];
animation1.duration= 0 ;
animation1.fromValue=[NSNumber numberWithFloat:1.0];
animation1.toValue=[NSNumber numberWithFloat:0.0];
animation1.beginTime = 3;
animation1.removedOnCompletion = NO;
animation1.fillMode = kCAFillModeBoth;
animation1.additive = NO;
animation1.autoreverses = NO;
这是我动摇的动画,它没有做任何事情:
CAKeyframeAnimation * shakeAnim = [ CAKeyframeAnimation animationWithKeyPath:@"transform" ] ;
shakeAnim.values = @[ [ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(-10.0f, 0.0f, 0.0f) ], [ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(10.0f, 0.0f, 0.0f) ] ] ;
shakeAnim.autoreverses = YES ;
shakeAnim.repeatCount = 2.0f ;
shakeAnim.duration = 0.07f ;
shakeAnim.beginTime = 0;
shakeAnim.fillMode = kCAFillModeBoth;
这里我添加了动画:
CALayer *overlayLayer1 = [CALayer layer];
[overlayLayer1 addSublayer:subtitle1Text];
overlayLayer1.frame = CGRectMake(0, 0,
self.screenSize.width, self.screenSize.height);
[overlayLayer1 setMasksToBounds:YES];
[overlayLayer1 addAnimation:shakeAnim forKey:@"transform" ] ;
[overlayLayer1 addAnimation:animation1 forKey:@"opacityOUT"];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0, 0, self.screenSize.width, self.screenSize.height);
videoLayer.frame = CGRectMake(0, 0, self.screenSize.width, self.screenSize.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:overlayLayer1];
对于摇晃不起作用的任何想法都会喜欢。