n.e*_*ind 13 iphone animation cocoa-touch objective-c
我想知道如何设置动画重复.重复次数需要由变量确定.在以下代码中,变量int newPage应确定动画重复的频率.
我尝试了这个,但动画(采用块动画)只执行一次:
for (int temp = 1; temp <= newPage; temp++) {
[self animatePage];
}
Run Code Online (Sandbox Code Playgroud)
如果我编写以下代码,它就像我想要的那样工作,但这是硬编码的(即动画将重复两次)我无法看到如何更改此动画在代码中执行频率的方式并根据我的变量newPage:
[UIView animateWithDuration:0
delay:0.1
options:UIViewAnimationOptionCurveEaseIn
animations:^{[self animatePage];}
completion:^(BOOL finished){[self animatePage];}];
Run Code Online (Sandbox Code Playgroud)
我非常感谢有关如何重复相同动画的建议,而无需硬编码我希望重复此动画的次数.
编辑:
我试图实现以下代码,但实际上只会执行一个动画:
[UIView animateWithDuration:0
delay:1
options:UIViewAnimationOptionCurveEaseIn
animations:^{
[UIView setAnimationRepeatCount:2];
[self animatePage];
}
completion:nil];
Run Code Online (Sandbox Code Playgroud)
YaD*_*aDa 32
有同样的问题 - 你错过了一个'UIViewAnimationOptionRepeat'
这应该工作:
[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];
Run Code Online (Sandbox Code Playgroud)
为我做了诀窍.
你试过设置repeatCount吗? + (void)setAnimationRepeatCount:(float)repeatCount
我已经尝试了以下代码块,它肯定会为我重复2x(我是一个UITextView,在X dir中放大2倍,在Y dir放大3倍):
[UIView animateWithDuration:2
delay:0.1
options:UIViewAnimationOptionCurveEaseIn
animations:^{ [UIView setAnimationRepeatCount:2];
l.transform = CGAffineTransformMakeScale(2,3); } completion:nil];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15023 次 |
| 最近记录: |