2014-01-27 200 views
0

正常工作在我的應用我有一個故事板,我用「自動版式」選項;問題是,如果我還可以將一些與UIImageView的動畫以這種方式:的iOS:自動佈局不與動畫

[UIView animateWithDuration:1.0 animations:^{ 

    [image setCenter:CGPointMake(300,200)]; 
}]; 

當動畫完成在原來的位置的圖像迴歸,爲什麼???如果我沒有檢查自動佈局選項,它工作正常。 你能告訴我,我是否可以使用自動佈局管理動畫?有什麼辦法做到這一點?

+0

可能重複[我如何動畫約束的變化?(http://stackoverflow.com/questions/12622424/怎麼辦 - 我 - 動畫 - 約束變化) –

回答

1

自動佈局的第一條規則! 您無法使用AutoLayout更改視圖的框架或中心。

爲了動畫,你必須設置您將使用動畫,然後改變約束約束的視圖。

self.heightConstraint = [NSLayoutConstraint constraintWithItem:self.theView 
attribute: 
relatedBy: 
toItem: 
attribute: 
multiplier: 
constant:]; 
// set up the rest 

[self.view addConstraint:self.heightConstraint]; 

然後動畫它...

self.heightConstraint.constant = 20; 

[UIView animateWithDuration:2.0 
animations:^() { 
    [self.view layoutIfNeeded]; 
}]; 
+0

好,我會嘗試.... – CrazyDev

+0

什麼是自動版式的第二條規則? – jrturton

+0

AutoLayout的第二條規則。您無法使用AutoLayout更改視圖的框架或中心。 – Fogmeister