![](/img/trans.png)
[英]UIView animateWithDuration doesn't work with Rect width/height animation
[英]AnimateWithDuration doesn't work as expected
我正在嘗試運行一個示例來測試此功能。 我在storyBoard中有一個標簽和一個按鈕,並且在視圖控制器中引用了標簽的底部約束。 當我使用按鈕時,我希望標簽隨動畫一起移動,但沒有動畫就移動。 這是按鈕的代碼:
- (IBAction)sd:(id)sender {
[UIView animateWithDuration:0.5f animations:^{
self.constraint.constant += 50;
}];
}
我知道如何快速使用它,但是我在目標c中遇到問題,我知道這只是一個小錯誤……有什么幫助嗎?
這不是對受自動版式約束的UI組件進行動畫處理的正確方法。 您應該首先更新約束,然后在動畫塊中調用layoutIfNeeded
:
self.constraint.constant += 50;
[UIView animateWithDuration:0.5f animations:^{
[self.view layoutIfNeeded];
}];
用這個
self.constraint.constant += 50;
[UIView animateWithDuration:0.5f
animations:^{
[self.view layoutIfNeeded];
}];
嘗試使用此setNeedsLayout在某些情況下會有所幫助。
self.constraint.constant += 50;
[UIView animateWithDuration:0.5f
animations:^{
[self.view setNeedsLayout];
}
completion:^(BOOL finished) {
}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.