[英]How to add two CABasicAnimations on a single uiview's layer?
我正在為uiview的圖層添加動畫,發生的事情就是當我添加第一個動畫時它正在經歷,但是添加第二個動畫會刪除第一個動畫,我怎么能平行地添加兩個cabasicanimation? 請幫我怎么做。
-(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
請提供您的建議,我應該如何實施。
您需要使用CAAnimationGroup
將所有動畫組合在一起,然后僅將動畫組應用於視圖。
使用此技術,您可以在不同的鍵路徑上同時運行多個動畫,並且可以在同一個鍵路徑上安排多個動畫以按順序運行(通過設置適當的時序詳細信息)。
請注意,您不能使用動畫組或任何其他方法同時在同一個鍵路徑上運行多個動畫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.