当使用 UINavigationController 进行边缘滑动时,CABasicAnimation 会重置

CABasicAnimation resets when edge swiping with UINavigationController

我的 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,我缺少什么?

设置 fillModeremovedOnCompletion 的整个技巧是无稽之谈 - 这是一个糟糕的建议,但它本身已经成为很多答案,但它是完全错误的。动画是一回事;罗盘层的实际变换是另一个。您已经应用了动画,但您忘记了 设置 transform 来匹配它。因此,当手势开始并且动画从图层中移除时,指南针将显示为实际旋转(并且变化显示为跳跃)。

感谢上面的 matt,我意识到我遗漏了以下行:

compass.transform = CGAffineTransformMakeRotation(-1*(((-windBearing+180) * M_PI) / 180));