使用UIView animateWithDuration:延迟:Xcode [英] using UIView animateWithDuration: delay: Xcode
问题描述
我正在尝试使用
[UIView animateWithDuration:1 delay:2 options:UIViewAnimationOptionCurveEaseIn animations:^{
} completion:^ (BOOL completed) {} ];
无论我为延迟输入多少,都不会延迟.
我试图让一系列按钮在触摸另一个按钮时一个接一个地淡入淡出.因此,我使用一系列具有各种延迟时间长度的UIView动画,但是无论我输入什么时间延迟,它们都同时显示.有人有建议吗?
however no matter what number I put for the delay, there is no delay.
I am trying to have a series of buttons fade in one after the other when another button is touched. So I use a series of UIView animate with various lengths of delay but they all show up at the same time no matter what time delay I enter. Does anyone have some suggestions?
推荐答案
首先,值animateWithDuration
和delay
是 float
值,应为1.0
和2.0
意见:如果您的代码位于ViewDidLoad
方法中,请尝试将其移至单独的函数
Opinion: if your code is at the ViewDidLoad
Method, try to move it to a separated function
第二,如果您无法在这种情况下执行此操作,则跳到另一个位置,或者四处走走,例如使用
Secondly if you are not able to do it by this context, jump to another, or make a walk around such as using
performSelector:withObject:afterDelay
另一种解决方法是将delay
设置为0,并将随后的UIView
动画块放置在先前animateWithDuration
语句的completion
块中
Another walk around is to set the delay
to 0, and place the subsequent UIView
animation blocks in the completion
block of the previous animateWithDuration
statements
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
animations:^(void) {
//Leave it empty
}
completion:^(BOOL finished){
// Your code goes here
[UIView animateWithDuration:1.0 delay:0.0 options:
UIViewAnimationOptionCurveEaseIn animations:^{
} completion:^ (BOOL completed) {}];
}];
PS::不支持对某些属性进行动画处理,例如在动画块中设置文本,因此在延迟结束后,动画将立即开始更改文本,因为该更改不可动画
PS: some properties are not supported to be animated such as setting the text within the animation block so after the delay is over, the animations begin which immediately changes the text as that change is not animatable.
在文本动画的情况下,要执行所需的操作,请按如下所示更改完成区中的文本:
in the text animation case, To do what you want, change the text in the completion block as follows:
[UIView animateWithDuration:1.0
delay:2.0
options: UIViewAnimationOptionTransitionCrossDissolve
animations:nil
completion:^{
lbl.text = @"My text" ;
}];
backgroundColor
也在UIView
中否设置了动画.而是使用视图的layer
的backgroundColor
属性:
Also backgroundColor
is NOT animated in UIView
. Instead, use backgroundColor
property of the view's layer
:
[[controller layer] setBackgroundColor:[[UIColor anyColor] CGColor]];
这篇关于使用UIView animateWithDuration:延迟:Xcode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!