我有一个uiview数组,我用下面的代码动画:
for (int i = 0; i<(int)viewArray.count; i++) {
UIView *view = [viewArray objectAtIndex:i];
CALayer *layer = view.layer;
//animate the layer
}
我的问题是,有没有办法在每个动画之间有一个延迟,这样,例如,它在数组中动画一个UIView,下一个动画在0.2秒左右开始?任何帮助将非常感激!
您可以尝试下面的
float timeDelay = 0.2
float duration = YOUR_DURATION
for (int i = 0; i<(int)viewArray.count; i++) {
UIView *view = [viewArray objectAtIndex:i];
//animate the layer
[UIView animateWithDuration:duration delay:(i+1)*timeDelay
options: {Check UIView Class Reference on developer.apple.com}
animations:^{
[view.layer fantastic animation here];
} completion^(BOOL finised){
if(finished){
//Leave blank if nothing, good practice to implement debuging here or post animation processes here (like removing a subview from a super)
}
}];
}
请记住,如果你把你的程序发送到后台,它可能会破坏你的动画,所以一定要在你的应用程序委托中调用这个方法:
- (void)applicationWillEnterForeground:(UIApplication *)application;
希望有所帮助
用这个家伙:
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
使用第二个参数。在循环中,调用该函数,将一个递增的数字传递给该参数。