如何在单个uiview的图层上添加两个CABasicAnimations?

时间:2014-04-25 09:40:24

标签: ios core-animation caanimation

我正在为uiview的图层添加动画,发生的事情是,当我添加第一个动画时,它正在经历,但添加第二个动画会删除第一个动画,如何平行添加两个cabasicanimation?请帮我怎么做。

enter image description here

-(void)viewDidAppear:(BOOL)animated{
if (![ViewController weakDevice]) {
    _imageView_BlurBackground.image = _blurBackgroundImage;
}else{
    _imageView_BlurBackground.backgroundColor = [UIColor colorWithRed:96.0/255.0      green:96.0/255.0 blue:96.0/255.0 alpha:0.9];
}
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.40f] CGColor];
maskLayer.contents = (id)[[UIImage imageNamed:@"Mask3.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(0, -_creditListView.frame.size.height, _creditListView.frame.size.width, _creditListView.frame.size.height*2);

// Animate the mask layer's horizontal position
CABasicAnimation *maskAnim = [CABasicAnimation animationWithKeyPath:@"position.y"];
maskAnim.toValue = [NSNumber numberWithFloat:_creditListView.frame.size.height];
maskAnim.fromValue = [NSNumber numberWithFloat:0.0];

maskAnim.repeatCount = HUGE_VAL;
maskAnim.duration = 6.0f;
[maskLayer addAnimation:maskAnim forKey:@"slideAnim"];
_creditListView.layer.mask = maskLayer;

[_scrollView_CreditList setContentSize:CGSizeMake(_scrollView_CreditList.frame.size.width,  _imageView_CreditList.frame.size.height+20)];
[self performSelectorOnMainThread:@selector(startRolling) withObject:nil waitUntilDone:YES];}

更新

白色高光的第二个向下闪光应该在第一个向下闪光达到其向下运动的80%时开始,然后是相同模式的后续闪光。

我的视图层次结构是

CreditViewController--->
     View---->       
          BlurBackground UIView
          FirstAnimationView--->
                  ScrollView
                  ImageView
          SecondAnimationView--->
                  ScrollView
                  ImageView

请告诉我你的建议,我该如何实施。

1 个答案:

答案 0 :(得分:2)

您需要使用CAAnimationGroup将所有动画组合在一起,然后将动画组仅应用于视图。

使用此技术,您可以在不同的键路径上同时运行多个动画,并且可以在同一个键路径上安排多个动画按顺序运行(通过设置适当的时序详细信息)。

请注意,您不能使用动画组或任何其他方法同时在同一个键路径上运行多个动画。