OGeek|极客世界-中国程序员成长平台

标题: ios - 动画转换大型 UIImageView 时性能不佳 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:14
标题: ios - 动画转换大型 UIImageView 时性能不佳

我正在为我们的游戏构建一个标题序列,其中每个标题都是一个大约半屏幕大小的视网膜图像,我使用 UIImageView 显示它。

随着它逐渐增长和淡入/淡出,标题序列具有简单的 3 个阶段:

// 1. Fade in and grow
[UIView animateWithDuration:1.0f animations:^{
    titleImageView.alpha = 1.0f;
    titleImageView.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
} completion:^(BOOL finished) {

    // 2. Stay opaque, grow a little more
    [UIView animateWithDuration:2.0f animations:^{
        titleImageView.transform = CGAffineTransformMakeScale(1.1f, 1.1f);
    } completion:^(BOOL finished) {

        // 3. Fade out, grow even further
        [UIView animateWithDuration:2.0f animations:^{
            titleImageView.alpha = 0.0f;
            titleImageView.transform = CGAffineTransformMakeScale(1.3f, 1.3f);
        } completion:nil];

    }];

}];

在每个动画阶段开始时,都会出现一两帧掉线的卡顿现象。在 iPhone 4 和 iPad 3 等旧硬件上尤其明显,但在 iPad Air 上甚至更明显,这令人惊讶。

一些扣除:

另外请注意,我在后台运行了一些 OpenGL ES 图形(这是一个在前台使用 UIKit 控件的游戏),但过去并没有造成问题...



Best Answer-推荐答案


所以,它有点难看,但我同时用两种方法解决了它:

  1. 我将级联 UIView 动画转换为单个 CALayer keyframed animation这样它们是连续的,而不是在每个阶段停止,调用完成处理程序,并开始一个新的动画。正如 Brian Nickel 指出的那样,也许这会阻止他们“安定下来”并以新的比例重新渲染。
  2. 但这并没有阻止第一次卡顿,因为它显示了每个新的 UIImage。为了解决这个问题,我预先创建了所有 UIImageViews(总共 6 个),将它们添加到 superview,并将它们的 alphas 设置为零。图片不大,也没有太多,所以看起来还可以。

关于ios - 动画转换大型 UIImageView 时性能不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23998481/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4