我有三个UIView
我希望以某种顺序制作动画(它应该看起来像一个新闻自动收报机,有三个不同的标签从上方移动然后显示然后一直移动到外面风景)。现在整个过程应该无限重复。
这是我使用的代码:
[UIView animateWithDuration:5.0 delay:0 options:UIViewAnimationOptionRepeat| UIViewAnimationOptionCurveLinear animations:^
{
[morningPrayerView setFrame:CGRectMake(0, 0, 320, 30)];
[morningPrayerView setAlpha:1.f];
}
completion:^(BOOL finished)
{
[UIView animateWithDuration:5.0 delay:0 options:UIViewAnimationOptionRepeat| UIViewAnimationOptionCurveLinear animations:^{
[morningPrayerView setFrame:CGRectMake(0, 30, 320, 30)];
[morningPrayerView setAlpha:1.f];
} completion:^(BOOL finished) {
{
[UIView animateWithDuration:5.0 delay:0 options:UIViewAnimationOptionRepeat| UIViewAnimationOptionCurveLinear animations:^{
[middayPrayerView setFrame:CGRectMake(0, 0, 320, 30)];
[middayPrayerView setAlpha:1.f];
} completion:^(BOOL finished) {
{
[UIView animateWithDuration:5.0 delay:0 options:UIViewAnimationOptionRepeat| UIViewAnimationOptionCurveLinear animations:^{
[middayPrayerView setFrame:CGRectMake(0, 30, 320, 30)];
[middayPrayerView setAlpha:1.f];
} completion:^(BOOL finished) {
{
[UIView animateWithDuration:5.0 delay:0 options:UIViewAnimationOptionRepeat| UIViewAnimationOptionCurveLinear animations:^{
[eveningPrayerView setFrame:CGRectMake(0, 0, 320, 30)];
[eveningPrayerView setAlpha:1.f];
} completion:^(BOOL finished) {
{
[UIView animateWithDuration:5.0 delay:0 options:UIViewAnimationOptionRepeat| UIViewAnimationOptionCurveLinear animations:^{
[eveningPrayerView setFrame:CGRectMake(0, 30, 320, 30)];
[eveningPrayerView setAlpha:1.f];
} completion:^(BOOL finished) {
//this block is called when the animation is over
}];
} }];
} }];
} }];
} }];
}];
问题是只有第一个动画才能开始,其他动画都没有开始。
答案 0 :(得分:1)
恕我直言,UIViewAnimationOptionRepeat
开关意味着无限期地重复动画,因此你的第一个动画永远循环,永远不会调用完成处理程序。只需在方法中包装整个动画设置,删除重复开关,并在执行最后一个完成处理程序时再次调用该方法重复整个节目?像这样:
- (void) animateView {
[UIView animateWithDuration:5.0 animations:^{
// …
} completion:^(BOOL finished) {
[self animateView];
}];
}
这可能是一个保留周期,但只要你最终取消动画,它应该没问题。