2014-01-31 196 views
1

我無法弄清楚如何在iOS7中設置NSLayoutConstraint動畫持續時間。這裏是我的代碼:NSLayoutConstraint動畫持續時間iOS7

self.loadingViewTop.constant = -[[UIScreen mainScreen] bounds].size.height; 
self.loadingViewBottom.constant = [[UIScreen mainScreen] bounds].size.height; 

[UIView animateWithDuration:30.0f animations:^{ 
    [self.loadingView setNeedsUpdateConstraints]; 
}]; 
+0

可能重複(http://stackoverflow.com/questions/12926566/are-nslayoutconstraints-animatable) – Wain

+0

@iiFreeman我試過了。實際上如果你刪除[UIView animateWithDuration]代碼,視圖仍然動畫。我看不到任何可能的解決方案如何控制它。 – Dmitry

回答

1

哦,你忘了叫[self.view layoutIfNeeded];動畫塊

+0

我也試過了。它沒有任何區別。我認爲佈局約束在iOS7中表現有所不同。在iOS6中運行良好的代碼不再適用。 – Dmitry

+0

你檢查過你的常量是不是零? – iiFreeman

+0

好吧,我得到它的工作。這是正確的方法: self.loadingViewTop.constant = - [[UIScreen mainScreen] bounds] .size.height; self.loadingViewBottom.constant = [[UIScreen mainScreen] bounds] .size.height; [UIView animateWithDuration:30.0f動畫:^ {self.view layoutIfNeeded]; }]; – Dmitry

1

的解決方案裏面:[?是否NSLayoutConstraints動畫]的

self.loadingViewTop.constant = -[[UIScreen mainScreen] bounds].size.height; 
self.loadingViewBottom.constant = [[UIScreen mainScreen] bounds].size.height; 

[UIView animateWithDuration:30.0f animations:^{ 
    [self.view layoutIfNeeded]; 
}];