2017-07-28 96 views
0

我有下面的代碼以便延遲更改NSLayoutConstraint。價值在變化,但沒有延遲和動畫。請讓我知道這個代碼有什麼問題。NSLayoutConstraint更改不起作用

self.heightConstraint.constant = 100; 
[self.animatingView setNeedsUpdateConstraints]; 
[UIView animateWithDuration:3.0 delay:1.0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
    [self.animatingView layoutIfNeeded]; 
} completion:^(BOOL finished) { 

}]; 
+0

移除[self.animatingView layoutIfNeeded]; 從您的代碼。並檢查 – Nirmalsinh

+0

@Nirmalsinh:即使刪除它也不能工作。 – boom

回答

2

嘗試在animatingView的superview上調用layoutIfNeeded方法。

+0

感謝您的建議,它正在工作。但是,爲什麼要監督。 – boom

+0

您需要在父視圖中專門調用它,而不是具有附加約束的子視圖。這樣做會更新所有受限制的視圖,包括將其他視圖的動畫設置爲可能受限於您更改約束的視圖。 – Shubham

0

Remvoe此線

[self.animatingView setNeedsUpdateConstraints]

它將沒有動畫更新和 變化

[self.animatingView layoutIfNeeded]; to 

[self.view layoutIfNeeded]; 
0
[UIView animateWithDuration:3.0 delay:1.0 options:UIViewAnimationOptionCurveEaseOut animations:^{  
self.heightConstraint.constant = 100; 
} completion:^(BOOL finished) { 
}]; 

這將工作