2014-01-27 186 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