【问题标题】:How to make chain transitions? [closed]如何进行链式转换? [关闭]
【发布时间】:2013-03-07 00:07:08
【问题描述】:

我在屏幕上有 40 个 UIView 平铺对象。然后在视图控制器中,我有例程使用transitionFromView 消息翻转这些图块。如果我在循环中一次翻转它们,在模拟器上它看起来很平滑,但在 iPhone 上它正在努力翻转它们。那是因为 iPhone CPU/GPU 速度较慢,一次无法处理这么多的转换。所以我想要的是进行某种链式转换,最终在任何给定时间转换 5-10。现在每次翻转需要 0.4 秒。最简单的方法是什么?

【问题讨论】:

  • 应该没有这个问题。一旦您要求制作 40 个翻转视图的动画,就应该毫无困难地执行它。也许您应该向我们展示您的代码?也许你做错了。另外,用 Instruments 试试;它会告诉你问题出在哪里。
  • 好吧,代码相当大,修剪起来并不容易。在 > iPhone 4 上也不是问题。但我也必须支持 3GS。所以我真的需要链接这些动画,它也会产生一些很好的效果,而不是一次全部翻转。
  • 你能显示你做转换的循环吗
  • 尝试直接用 Core Animation 翻转它们(参见CABasicAnimation)。

标签: iphone ios5 uiview


【解决方案1】:

我可能会采取一种方法是一对一地错开动画。

只需在 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
}

【讨论】:

    【解决方案2】:

    UIView transition... 动画方法采用 completion 块。有你的链子。排列你的块并将它们设置为链中连续调用的完成块。

    或者构造一个分组动画。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-09
      • 2013-03-24
      • 1970-01-01
      • 2021-02-23
      • 2016-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多