我在屏幕上有40个UIView磁贴对象。然后,在视图控制器中,我有一个使用transitionFromView消息翻转这些瓦片的例程。如果我在循环中立即翻转它们,在模拟器上看起来很流畅,但在iPhone上它很难翻转它们。这是因为iPhone的CPU/GPU比较慢,不能同时处理这么多的转换。所以我想要的是进行某种链式转换,最终在任何给定的时间转换到5-10。现在每一次翻转需要0.4秒。做到这一点最简单的方法是什么?
发布于 2013-03-07 10:26:28
我可能会采取将动画一对一地错开的方法。
只需维护一个包含所有要动画化的视图的NSArray *views,并使用[self transformViewAtIndex:[NSNumber numberWithInt:0]];启动该序列
- (void)transformViewAtIndex:(NSNumber *)index {
// Make sure we're not out of bounds
if ([index intValue] >= [views count]) return;
// Get the view we want to work on
UIView *view = [views objectAtIndex:[index intValue]];
// Perform the animation
[UIView animateWithDuration:0.4 animations:^{ // Whatever duration you want
// ... This is where your actual transformation code goes
}];
// Schedule the next animation
NSNumber *newIndex = [NSNumber numberWithInt:[index intValue] + 1];
[self performSelector:@selector(transformViewAtIndex:) withObject:newIndex afterDelay:0.2]; // Set delay to a number that is effective
}发布于 2013-03-07 08:22:06
UIView transition...动画方法需要一个completion块。这就是你的链子。排列您的块,并将它们设置为链中连续调用的完成块。
或者构造成组的动画。
https://stackoverflow.com/questions/15260690
复制相似问题