重复的动画变量的次数 [英] Repeat an animation a variable number of times
问题描述
我想知道我怎么可以设置动画重复。需要由变量来确定重复次数。在下面的code,变量 INT NEWPAGE
应确定动画是如何经常重复。
我想这一点,但动画(其中采用了块动画)只执行一次:
为(INT TEMP = 1;温度< = NEWPAGE;临时++){
[个体经营animatePage]
}
如果我code以下,它就像我想它,但是这是很难codeD(即动画将重复两次),我看不到如何改变的方式这个动画是如何经常在code执行和数量按我可变NEWPAGE:
[UIView的animateWithDuration:0
延迟:0.1
选项:UIViewAnimationOptionCurveEaseIn
动画:^ {[个体经营animatePage];}
完成:^(BOOL完){[自animatePage];}];
我会为如何重复同样的动画的建议非常感激,而不必硬code我想重复这个动画的次数。
编辑:
我试图实现以下code,但只有一个动画实际上进行:
[UIView的animateWithDuration:0
延迟:1
选项:UIViewAnimationOptionCurveEaseIn
动画:^ { [UIView的setAnimationRepeatCount:2];
[个体经营animatePage] }
完成:无];
有同样的问题 - 你缺少an'UIViewAnimationOptionRepeat
这应该工作:
[UIView的animateWithDuration:0
延迟:1
选项:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionRepeat
动画:^ {
[UIView的setAnimationRepeatCount:2]; // **本应出现在块的开始**
[个体经营animatePage] }
完成:无];
奏效了我。
I was wondering how I can set an animation to repeat. The number of repetitions needs to be determined by a variable. In the following code, the variable int newPage
should determine how often the animation is repeated.
I tried this, but the animation (which employs a block animation) was only executed once:
for (int temp = 1; temp <= newPage; temp++) {
[self animatePage];
}
If I code the following, it works like I want it to, but this is hardcoded (i.e. the animation will be repeated twice) and I can't see a way of how to change the number of how often this animation is executed in code and according to my variable newPage:
[UIView animateWithDuration:0
delay:0.1
options:UIViewAnimationOptionCurveEaseIn
animations:^{[self animatePage];}
completion:^(BOOL finished){[self animatePage];}];
I'd be very grateful for suggestions of how to repeat the same animation without having to hardcode the number of times I want this animation to be repeated.
EDIT:
I tried to implement the following code, but only one animation will actually be carried out:
[UIView animateWithDuration:0
delay:1
options:UIViewAnimationOptionCurveEaseIn
animations:^{
[UIView setAnimationRepeatCount:2];
[self animatePage];
}
completion:nil];
Had the same problem - you were missing an an'UIViewAnimationOptionRepeat'
This should work:
[UIView animateWithDuration:0
delay:1
options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionRepeat
animations:^{
[UIView setAnimationRepeatCount:2]; // **This should appear in the beginning of the block**
[self animatePage];
}
completion:nil];
Did the trick for me.
这篇关于重复的动画变量的次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!