2014-10-29 102 views
1

我想在MAGNIFY圖標IOS設置約束的動畫圖標

執行下列約束動畫在我希望我的圖標是在我的屏幕的右邊,然後將其移動到左邊開始我文本框:

___________________ 
|___________________|   O- 

to 
    ___________________ 
O- |___________________|  

所以我所做的就是建立在優先級爲1000 的圖標,我的上海華權約束的,在優先級上的圖標添加其他約束B,我的文本框的左側750

然後當我想要perfo RM我的動畫我刪除約束A,所以我希望圖標移動到我的texfield的左側,但它沒有移動

如何做到這一點?

約束答:

enter image description here

約束B:

[UIView animateWithDuration:0.5 animations:^{ 

    self.view.alpha = 1; 

} completion:^(BOOL finished) { 

    //animating the icon 
    [self.view removeConstraint:_loupeSuperviewLeftMargin];//remove constraint A 
    [self.view setNeedsUpdateConstraints]; 

    UIView animateWithDuration:0.5f animations:^{ 
     [self.view invalidateIntrinsicContentSize]; 
     [self.view layoutIfNeeded]; 
    }]; 
}]; 
+0

嘗試在視圖上調用invalidateIntrinsicContentSize以使其重新計算約束。 – Gismay 2014-10-29 15:51:53

+0

您是否需要將文本字段向右移動以爲圖標在其新位置騰出空間?你對文本字段有什麼限制? – rdelmar 2014-10-29 16:17:46

+0

texfield位於我的超級視圖中,我希望圖標在其左側滑動。調用invalidateIntrinsicContentSize什麼也沒做 – Mathieu 2014-10-29 16:19:41

回答

1

它的工作對我來說,如果我把圖標:

enter image description here

動畫的一些代碼(我爲我的te使用了一個按鈕ST)這兩個約束標籤(低優先級的約束可以有任何優先級長達749 - 如果我使用750,這兩種觀點消失),

enter image description here

enter image description here

然後在代碼中,我刪除了高優先級的一個,

- (IBAction)moveButton:(id)sender { 
    [self.view removeConstraint:self.rightCon]; // rightCon is the high priority constraint 
    [UIView animateWithDuration:1 animations:^{ 
     [self.view layoutIfNeeded]; 
    }]; 

} 

確保您撥打removeConstraint上無論大家認爲是有他們之間的間隔限制這兩種觀點的上海華 - 它是上海華說擁有這個約束。

+0

好吧我和你一樣,除了在我的情況下,第一個約束的第一個項目是superview.trailing,而不是按鈕 – Mathieu 2014-10-29 16:52:43

+1

@Mathieu,你的問題可能是這一行,[_searchIcon removeConstraint:_iconSuperviewLeftMargin]; 。這兩個視圖之間的約束屬於superview,所以_searchIcon不擁有該約束,因此無法刪除它。 – rdelmar 2014-10-29 16:55:20

+0

我編輯我的帖子來添加詳細信息,它仍然不起作用 – Mathieu 2014-10-29 17:05:23