gpt4 book ai didi

objective-c - 核心动画动画滞后

转载 作者:行者123 更新时间:2023-11-29 04:35:01 25 4
gpt4 key购买 nike

我正在尝试使用核心动画淡入一些 View 。一切都很好,直到第四个或第五个 View 淡入为止。动画停止,几秒钟后,其余 View 仅显示在屏幕上(没有动画发生)。我在第三代iPad上进行了测试,所以这不可能是硬件过时的问题。代码:

viewDidLoad

- (void)viewDidLoad {
[super viewDidLoad];
self.subViews = self.view.subviews;

for (UIView *view in self.subViews) {
view.backgroundColor = [UIColor clearColor];
PhotoFrame *photoFrame = [[PhotoFrame alloc] init];
photoFrame.photo.image = [UIImage imageNamed:[NSString stringWithFormat:@"test%d.jpg", arc4random() % 6 + 1]];
[view addSubview:photoFrame];
view.layer.opacity = 0;
}
}

viewDidAppear

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self startAnimations];
}

开始动画

- (void)startAnimations {
int count = 1;
for (UIView *view in self.subViews) {
CALayer *animationLayer = view.layer;

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.fromValue = @0.0;
animation.toValue = @1.0;
animation.duration = 0.3;
animation.beginTime = CACurrentMediaTime() + count * 0.3;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;

[animationLayer addAnimation:animation forKey:@"opacityAnimation"];
count++;
}
}

希望大家能够帮助我。

最佳答案

我建议切换到 UIView 动画方法,例如 animateWithDuration:animations: ,或者在提交动画时将属性设置为其最终值,而不是使用 removedOnCompletion = TRUE .正如我在上面的评论中所说,removedOnCompletion 实际上使动画保持事件状态,并应用于渲染的每个帧。我发现当有很多动画处于事件状态时,速度会变慢。

关于objective-c - 核心动画动画滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11179717/

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