gpt4 book ai didi

ios - 当不再显示 UIViewController 时如何继续 CAKeyframeAnimation?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:20:04 35 4
gpt4 key购买 nike

我正在使用以下代码开始基本动画(遵循路径的 UIImageView):

CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
bounceAnimation.path = cgpath;
bounceAnimation.duration = 40.0;
bounceAnimation.rotationMode = kCAAnimationRotateAuto;
[img.layer addAnimation:bounceAnimation forKey:@"animateLayer"];

动画效果很好。

但是当我转到另一个 UIViewController 然后回到这个 UIViewController 时,我的 UIImageView 不再可见,动画也不再运行。

看起来只要我离开当前的 UIViewController,动画就停止了。

有没有办法避免这种行为?

如有任何帮助,我们将不胜感激。

问候,亚历克斯

更多详情:

我添加了一个计时器,它在动画 UIImageView 下绘制一些东西。这是此计时器调用的代码:

CALayer* _l=_v.layer.presentationLayer; // _v is my animated UIImageView
CGRect r=_l.frame;
img.center=CGPointMake(r.origin.x+r.size.width/2.0, r.origin.y+r.size.height/2.0);

一旦我更改了当前的 UIViewController,img.center 就位于我的 UIImageView 的初始位置下方 => UIIMageView 不再移动了:(

最佳答案

确保当你离开你的 View Controller 时它不会被释放

在动画所在的viewController中添加:

- (void)dealloc {
NSLog(@"did get deallocated");
}

然后在您的动画中检查 fillMode 属性 kCAFillModeBothkCAFillModeForward:

bounceAnimation.fillMode = kCAFillModeBoth;

例子

CALayer * layer       = [CALayer layer];
layer.anchorPoint = CGPointZero;
layer.frame = self.creator.animationLayer.bounds;
layer.backgroundColor = [UIColor clearColor].CGColor;
layer.opacity = 0.f;
layer.contentsGravity = kCAGravityResizeAspectFill;
layer.contents = (__bridge id)image;

关于ios - 当不再显示 UIViewController 时如何继续 CAKeyframeAnimation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26377124/

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