2014-04-25 69 views
0

我加入动画,一个UIView的层,什么情况是,当我第一次添加动画它正在经历的,但添加第二个动画删除第一位的,我怎么能平行添加两个cabasicanimation?请帮助我如何做到这一点。如何在单个uiview的图层上添加两个CABasicAnimations?

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 

请提供您的建议,我应该如何实现这一点。

+0

http://stackoverflow.com/questions/17764375/sequence-animation-using-caanimationgroup –

+0

“但添加第二个动画删除第一个”是两个动画动画相同的关键路径? –

+0

是的,他们使用相同的键路径。 –

回答

2

您需要使用CAAnimationGroup将所有动画结合在一起,然后应用只是动画组的观点。

使用这种技术,你可以有不同的keypaths多个动画同时运行,你可以安排在同一的keyPath多个动画顺序运行(通过设置适当的时机详细信息)。

注意,你不能使用动画组或任何其他方式在同一时间对同一的keyPath运行多个动画。

+0

我不认为它可以解决我的问题。因为在第二组动画开始时,第一组动画也会停止。但我需要这两个动画一起工作。 –

+0

每个动画都是针对不同的产权? – Wain

+0

实际上,我有一个使用position.y ketPath滚动的动画,当第一个动画完成90%的屏幕高度时,另一个动画从顶部弹出而不会影响第一个动画,这不会发生。当我使用相同keyPath添加第二个动画时,第一个动画将被删除。 –

相关问题