2013-02-27 136 views
-2

setAnimationDuration方法对我的代码没有任何影响,My Animation太快了。下面是代码为什么setAnimationDuration没有效果,我的动画太快

[UIView beginAnimations:nil context:nil];  
image1.frame=CGRectMake(0, 0, 0,image1.frame.size.height); 
image2.frame=CGRectMake(image2.frame.size.width, 0, 0,image2.frame.size.height); 
[UIView setAnimationDuration:10]; 
[UIView setAnimationDelegate:self]; 
[UIView commitAnimations]; 

回答

4

您需要更改动画属性前将持续时间值。

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:10]; 
image1.frame=CGRectMake(0, 0, 0,image1.frame.size.height); 
image2.frame=CGRectMake(image2.frame.size.width, 0, 0,image2.frame.size.height); 
[UIView setAnimationDelegate:self]; 
[UIView commitAnimations]; 

内的UIView的状态苹果类的引用的方法setAnimationDuration讨论:

而且你必须调用此方法改变你的观点的动画属性之前。默认值是0.2秒。

这就是为什么你得到非常快的动画。

这种风格的动画已经从ios4中泄露出来,所以如果上述不起作用,尝试使用新的动画块风格。

+0

谢谢,正如你所说,现在它工作 – Tung 2013-02-27 09:40:30

0

使用添加动画您的看法:

[UIView animateWithDuration:2.0 animations:^() 
{ 
    //Your code here 
}]; 

或者使用这种方法:

[UIView transitionWithView:super.view duration:1.0 options:UIViewAnimationOptionTransitionCurlUp animations:^ 
    { 
     //your code here 
    }completion:NULL 
    ];