【问题标题】:iOS - Cancel constraints animationiOS - 取消约束动画
【发布时间】:2015-09-13 12:16:32
【问题描述】:

我以通常的方式为约束设置动画:

centerXsettingsBtnConstraint.constant = aValue;

[UIView animateWithDuration:.5
                 animations:^{

                      [self.view layoutIfNeeded];

               } completion:^(BOOL finished) {
                      isAnimating = NO;}];

当我旋转设备时,我想取消此动画并使用新值更新约束。

我试着打电话

[self.view.layer removeAllAnimations];

但动画仍然继续,直到设备的旋转结束。只有这样我才能使用新的约束进行更新,但是在旋转过程中,屏幕上一片混乱。

有没有办法取消约束动画?

【问题讨论】:

    标签: ios xcode6 autolayout uiviewanimation


    【解决方案1】:

    您必须在每个子视图上调用 remove.. 方法:

    [self.view.layer removeAllAnimations];
    

    我将使用 Swift:

    for eachView in self.view.subviews {
        eachView.layer.removeAllAnimations()
    }
    

    【讨论】:

    • 你有一个替代选项:这可能会回答这个问题,但如果 evidence 支持它会更有帮助,例如一个简短的程序,或者一个文档或规范的链接。
    【解决方案2】:

    您需要删除指定视图上的动画,该视图的约束或属性在该特定动画中发生更改。

    在应用 centerXsettingsBtnConstraint 的视图上调用 removeAllAnimations()

    不需要在每个子视图上调用 removeAllAnimations()。

    如果您找不到特定的视图,请尝试打印 someView.layer.animationKeys(),您将找到应用了动画的视图。

    【讨论】:

      【解决方案3】:

      对于斯威夫特: 这将有助于停止约束的动画

      yourComponent.layer.removeAnimation(forKey: "position")
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-16
        • 1970-01-01
        • 2017-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多