<legend id='oHbhL'><style id='oHbhL'><dir id='oHbhL'><q id='oHbhL'></q></dir></style></legend>

<tfoot id='oHbhL'></tfoot>
      • <bdo id='oHbhL'></bdo><ul id='oHbhL'></ul>

      <i id='oHbhL'><tr id='oHbhL'><dt id='oHbhL'><q id='oHbhL'><span id='oHbhL'><b id='oHbhL'><form id='oHbhL'><ins id='oHbhL'></ins><ul id='oHbhL'></ul><sub id='oHbhL'></sub></form><legend id='oHbhL'></legend><bdo id='oHbhL'><pre id='oHbhL'><center id='oHbhL'></center></pre></bdo></b><th id='oHbhL'></th></span></q></dt></tr></i><div id='oHbhL'><tfoot id='oHbhL'></tfoot><dl id='oHbhL'><fieldset id='oHbhL'></fieldset></dl></div>

      <small id='oHbhL'></small><noframes id='oHbhL'>

        CABasicAnimation 旋转返回原始位置

        CABasicAnimation rotate returns to original position(CABasicAnimation 旋转返回原始位置)
        <i id='kZ4rR'><tr id='kZ4rR'><dt id='kZ4rR'><q id='kZ4rR'><span id='kZ4rR'><b id='kZ4rR'><form id='kZ4rR'><ins id='kZ4rR'></ins><ul id='kZ4rR'></ul><sub id='kZ4rR'></sub></form><legend id='kZ4rR'></legend><bdo id='kZ4rR'><pre id='kZ4rR'><center id='kZ4rR'></center></pre></bdo></b><th id='kZ4rR'></th></span></q></dt></tr></i><div id='kZ4rR'><tfoot id='kZ4rR'></tfoot><dl id='kZ4rR'><fieldset id='kZ4rR'></fieldset></dl></div>

            <tbody id='kZ4rR'></tbody>
            <tfoot id='kZ4rR'></tfoot>

            1. <small id='kZ4rR'></small><noframes id='kZ4rR'>

              • <bdo id='kZ4rR'></bdo><ul id='kZ4rR'></ul>
                • <legend id='kZ4rR'><style id='kZ4rR'><dir id='kZ4rR'><q id='kZ4rR'></q></dir></style></legend>
                  本文介绍了CABasicAnimation 旋转返回原始位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在使用 CABasicAnimation 旋转 CALayer 并且工作正常.问题是,当我尝试旋转同一图层时,它会在旋转之前返回到原来的位置.我的预期输出是,对于下一次轮换,它应该从它结束的地方开始.这是我的代码:

                  i'm rotating a CALayer using CABasicAnimation and works fine. The problem is, when I try to rotate the same layer, it returns back to its original position before it will rotate. My expected output is that, for the next rotation, it should start from where it has ended. Here's my code:

                  CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
                  animation.fromValue         = 0;
                  animation.toValue           = [NSNumber numberWithFloat:3.0];
                  animation.duration          = 3.0;
                  animation.timingFunction    = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
                  animation.removedOnCompletion = NO;
                  animation.fillMode          = kCAFillModeForwards;
                  animation.autoreverses      = NO;
                  [calayer addAnimation:animation forKey:@"rotate"];
                  

                  我的代码有什么遗漏吗?谢谢

                  Is there anything missing on my code? thanks

                  推荐答案

                  发生的情况是您在表示层中看到了动画.但是,这不会更新图层的实际位置.因此,一旦动画完成,您会看到图层原样,因为它没有改变.

                  What's happening is that you're seeing the animation in the presentation layer. However, that doesn't update the actual position of your layer. So, once the animation finishes, you see the layer as it was because it hasn't changed.

                  真的值得一读"核心动画渲染架构".否则这会很混乱.

                  It's really worth reading the "Core Animation Rendering Architecture". Otherwise this can be very confusing.

                  要修复它,请为您的 CABasicAnimation 设置一个委托,如下所示:

                  To fix it, set a delegate to your CABasicAnimation as follows:

                  [动画 setDelegate:self];

                  然后,创建一个方法来设置动画完成时所需的目标属性.现在,这是令人困惑的部分.您应该在 animationDidStart 而不是 animationDidStop 上执行此操作.否则,表示层动画将完成,当您看到原始位置的 calayer 时会闪烁,然后它会在没有动画的情况下跳转到目标位置.用 animationDidStop 试试,你就会明白我的意思了.

                  Then, create a method to set your target properties that you want when the animation completes. Now, here's the confusing part. You should do this on animationDidStart not animationDidStop. Otherwise, the presentation layer animation will finish, and you'll get a flicker as you see the calayer in the original position then it jumps - without animation - to the target position. Try it with animationDidStop and you'll see what I mean.

                  我希望这不会太混乱!

                  - (void)animationDidStart:(CAAnimation *)theAnimation
                  {
                      [calayer setWhateverPropertiesExpected];
                  }
                  

                  我后来发现 Apple 推荐了一种更好的方法来做到这一点.

                  I later discovered that Apple recommend a much better way to do this.

                  Oleg Begemann 在他的博文 在使用显式 CAAnimations 时防止图层恢复到原始值

                  基本上你所做的是在开始动画之前,记下图层的当前值,即原始值:

                  Basically what you do is before you start the animation, you take a note of the layer's current value, i.e., the original value:

                  // Save the original value
                  CGFloat originalY = layer.position.y;
                  

                  接下来,在层的模型上设置 toValue.因此,图层模型具有您将要执行的任何动画的最终值:

                  Next, set the toValue on the layer's model. Therefore the layer model has the final value of whatever animation you are about to do:

                  // Change the model value
                  layer.position = CGPointMake(layer.position.x, 300.0);
                  

                  然后,您将动画设置为 fromValue 是您上面提到的原始值:

                  Then, you set the animation up with the animation fromValue being that original value that you noted above:

                  CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position.y"];
                  
                  // Now specify the fromValue for the animation because
                  // the current model value is already the correct toValue
                  animation.fromValue = @(originalY);
                  animation.duration = 1.0;
                  
                  // Use the name of the animated property as key
                  // to override the implicit animation
                  [layer addAnimation:animation forKey:@"position"];
                  

                  请注意,为清楚起见,上面编辑中的代码是从 Ole Begemann 的博客中复制/粘贴的

                  这篇关于CABasicAnimation 旋转返回原始位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How To Create a Rotating Wheel Control?(如何创建转轮控件?)
                  iOS 6 rotations: supportedInterfaceOrientations doesn#180;t work?(iOS 6 旋转:supportedInterfaceOrientations 不起作用?)
                  How to avoid restarting activity when orientation changes on Android(如何在 Android 上的方向更改时避免重新启动活动)
                  UITabBarController Rotation Issues in ios 6(ios 6 中的 UITabBarController 旋转问题)
                  iOS: How to run a function after Device has Rotated (Swift)(iOS:设备旋转后如何运行函数(Swift))
                  How to rotate an image 90 degrees on iOS?(如何在 iOS 上将图像旋转 90 度?)

                      <tbody id='txUNU'></tbody>

                        <bdo id='txUNU'></bdo><ul id='txUNU'></ul>

                        <legend id='txUNU'><style id='txUNU'><dir id='txUNU'><q id='txUNU'></q></dir></style></legend><tfoot id='txUNU'></tfoot>
                      • <i id='txUNU'><tr id='txUNU'><dt id='txUNU'><q id='txUNU'><span id='txUNU'><b id='txUNU'><form id='txUNU'><ins id='txUNU'></ins><ul id='txUNU'></ul><sub id='txUNU'></sub></form><legend id='txUNU'></legend><bdo id='txUNU'><pre id='txUNU'><center id='txUNU'></center></pre></bdo></b><th id='txUNU'></th></span></q></dt></tr></i><div id='txUNU'><tfoot id='txUNU'></tfoot><dl id='txUNU'><fieldset id='txUNU'></fieldset></dl></div>

                        1. <small id='txUNU'></small><noframes id='txUNU'>