gpt4 book ai didi

ios - 如何在单个 uiview 层上添加两个 CABasicAnimations?

转载 作者:行者123 更新时间:2023-11-28 22:09:04 25 4
gpt4 key购买 nike

我正在向 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% 左右开始时开始,随后会按照相同的模式进行后续闪烁。

我的 View 层次是

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

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

最佳答案

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

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

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

关于ios - 如何在单个 uiview 层上添加两个 CABasicAnimations?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23289474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com