Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何检查NSLayoutConstraint是否正在设置动画_Ios_Objective C_Cocoa Touch_Core Animation_Nslayoutconstraint - Fatal编程技术网

Ios 如何检查NSLayoutConstraint是否正在设置动画

Ios 如何检查NSLayoutConstraint是否正在设置动画,ios,objective-c,cocoa-touch,core-animation,nslayoutconstraint,Ios,Objective C,Cocoa Touch,Core Animation,Nslayoutconstraint,我正在创建一个自定义NSLayoutConstraint子类,我需要知道布局约束的常量属性当前是否正在为内部状态处理设置动画。换句话说,我需要区分: { //no animation myLayoutConstraint.constant = 100; } 及 这样我就可以在动画中间处理接收消息的转角情况。这可能吗?实现这一点的唯一方法是在您想要访问它的任何地方使用一个布尔值,并执行类似于 { //no animation theView.animatingChange =

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

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


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

实现这一点的唯一方法是在您想要访问它的任何地方使用一个布尔值,并执行类似于

{ //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;
    }];
}

视图上的属性将立即更改为动画的“结束”值。在设置动画时,不会将其更改为所有中间值。只有屏幕上的图形是动画的。

我需要隐式地处理这个问题,使用constraint类的人不应该在外部设置任何内容。可以详细解释您试图实现的目标。您提出的问题“视图是否可能‘知道’它是否正在制作动画?”的答案很简单。不可能。但是你想达到什么目的呢。也许还有另一种方法可以做到这一点。我正在创建一个布局系统,它可以自然地打开和关闭视图(通过滑动标题等),并且我正在使用我编写的自定义NSLayoutConstraint类来完成这一点。目前,该系统在我自己的项目中运行得非常完美,但我想进一步了解它的状态,使其成为一个开源框架。这就是我想做这个的原因。
{ //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;
    }];
}