OGeek|极客世界-中国程序员成长平台

标题: ios - 如何检查 NSLayoutConstraint 是否动画 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 17:07
标题: ios - 如何检查 NSLayoutConstraint 是否动画

我正在创建一个自定义 NSLayoutConstraint 子类,我需要知道布局约束的 constant 属性当前是否正在为内部状态处理设置动画。也就是说,我需要区分:

{ //no animation
    myLayoutConstraint.constant = 100;
} 

{ //animated
    myLayoutConstraint.constant = 100;
    [UIView animateWithDuration:0.2 animations:^{
        [self.myViewThatHasTheConstraintAttached layoutIfNeeded];

    } completion:^(BOOL finished) {
        [...]
    }];
}

这样我就可以处理在动画中间接收消息的极端情况。这可能吗?



Best Answer-推荐答案


做到这一点的唯一方法是在您想要访问它的任何地方都有一个 bool 值并执行类似...

{ //no animation
    theView.animatingChange = NO;
    myLayoutConstraint.constant = 100;
}

{ //animated
    theView.animatingChange = YES;
    myLayoutConstraint.constant = 100;
    [UIView animateWithDuration:0.2 animations:^{
        [self.myViewThatHasTheConstraintAttached layoutIfNeeded];

    } completion:^(BOOL finished) {
        [...]
        theView.animatingChange = NO;
    }];
}

View 上的属性立即更改为动画的“结束”值。它在制作动画时不会更改为所有中间值。只是屏幕上的绘图是动画的。

关于ios - 如何检查 NSLayoutConstraint 是否动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20467844/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4