使用UINavigationController进行边缘滑动时,CABasicAnimation会重置 [英] CABasicAnimation resets when edge swiping with UINavigationController

查看:65
本文介绍了使用UINavigationController进行边缘滑动时,CABasicAnimation会重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 viewDidLoad 中有以下 CABasicAnimation ,用于内的视图控制器UINavigationController

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.duration = 1;
animation.additive = NO;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.fromValue = [NSNumber numberWithFloat:0];
animation.toValue = [NSNumber numberWithFloat:-1*(((-windBearing+180) * M_PI) / 180)];
[compass.layer addAnimation:animation forKey:@"90rotation"];

当我使用边缘轻扫手势缓慢向后导航时,动画会重置为初始状态相当刺耳。我将我的 fillMode 设置为 removedOnCompletion 设置为 NO ,我缺少什么?

When I use the edge swipe gesture to slowly navigate back, the animation resets to the initial state, which is quite jarring. I have my fillMode set and removedOnCompletion set to NO, what am I missing?

推荐答案

设置 fillMode 的整个技巧而 removedOnCompletion 是胡说八道-这是一个不好的建议,已经使自己成为很多答案,但这是完全错误的。动画是一回事;指南针层的实际转换是另一个。您已经应用了动画,但是忘记了设置变换 使其匹配。因此,当手势开始并将动画从图层中删除时,指南针以其实际旋转显示(并且更改显示为跳跃)。

This whole trick of setting the fillMode and the removedOnCompletion is nonsense - it's bad advice that has worked itself into a lot of answers, but it's totally wrong. The animation is one thing; the actual transform of the compass layer is another. You have applied the animation but you have forgotten to set the transform to match it. Therefore, when the gesture starts and the animation is removed from the layer, the compass is shown at its actual rotation (and the change appears as a jump).

这篇关于使用UINavigationController进行边缘滑动时,CABasicAnimation会重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆