【问题标题】:iOS - How to stop UIView animations at a particular frame [duplicate]iOS - 如何在特定帧停止 UIView 动画[重复]
【发布时间】:2012-10-30 13:59:29
【问题描述】:

可能重复:
Cancel a UIView animation?

我需要停止 UIView 动画。我知道我可以使用[object.layer removeAllAnimations]; 但这不会停止动画,而是“跳过”它。所以,如果我的原始动画是:

[UIView animateWithDuration:8.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^ (void) {
        [ingredient setFrame:CGRectMake(20, 200, 34, 45)];
    } completion:^ (BOOL finished) {
        NSLog(@"Completed");
    }];

对象成分将具有动画完成后的帧。相反,我希望对象在特定点停止,而动画不完整。

【问题讨论】:

标签: ios animation frame


【解决方案1】:

如果您想暂停,但不打算重新开始,请尝试:

CALayer *objectPresentationLayer = [object.layer presentationLayer];
object.layer.transform = objectPresentationLayer.transform;
[object.layer removeAllAnimations];

如果您想暂停和恢复动画,请查看 Apple 问答: https://developer.apple.com/library/ios/#qa/qa2009/qa1673.html

【讨论】:

  • 这似乎将动画移动到 ios 9 上的完成状态?
  • 对我也不起作用,但 progressView.layer.frame = progressView.layer.presentation()!.frame 确实起作用
猜你喜欢
  • 2022-12-07
  • 1970-01-01
  • 2023-04-08
  • 2019-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-25
  • 1970-01-01
相关资源
最近更新 更多