簡體   English   中英

如何檢查NSLayoutConstraint是否正在設置動畫

[英]How to check if NSLayoutConstraint is animating

我正在創建一個自定義NSLayoutConstraint子類,我需要知道布局約束的constant屬性當前是否在為內部狀態處理設置動畫。 換句話說,我需要區分:

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

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

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

這樣我就可以處理一些極端情況,以便在動畫中間接收消息。 這可能嗎?

做到這一點的唯一方法是在您要訪問的任何地方都設置一個布爾值,並執行類似的操作。

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

視圖上的屬性立即更改為動畫的“結束”值。 在設置動畫時,不會將其更改為所有中間值。 只是屏幕上的圖形是動畫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM