如何使UIImageView动画节能?

时间:2014-07-29 21:18:01

标签: ios animation uiimageview profiling

所以我在我的代码中有这个方法,在我的应用程序中显示了一个非常好的加载器。我被告知这样做的最好方法是使用UIImageView。

我设置了所有参数,我想我已经涵盖了我需要的所有内容。装载机继续旋转'在我的应用程序的后台,相应的UI元素调整他们的alpha,基于我需要显示加载器的时间,在UITableView的情况下。

然而,当在iOS 7上进行测试并分析能量诊断和时间分析时,我发现它需要大量的应用程序。有什么方法可以提高效率吗?

- (void)displayLoadingCircle:(BOOL)display {

    UIView *placeholderView = [[UIView alloc] initWithFrame:self.view.bounds];
    UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(94, 240, 125, 125)];
    [animatedImageView setContentMode:UIViewContentModeScaleToFill];
    [animatedImageView setAlpha:0.7f];

    animatedImageView.animationImages = [NSArray arrayWithObjects:
                                         [UIImage imageNamed:@"loader-1 (dragged).png"],
                                         [UIImage imageNamed:@"loader-2 (dragged).png"],
                                         [UIImage imageNamed:@"loader-3 (dragged).png"],
                                         [UIImage imageNamed:@"loader-4 (dragged).png"],
                                         [UIImage imageNamed:@"loader-5 (dragged).png"],
                                         [UIImage imageNamed:@"loader-6 (dragged).png"],
                                         [UIImage imageNamed:@"loader-7 (dragged).png"],
                                         [UIImage imageNamed:@"loader-8 (dragged).png"],
                                         [UIImage imageNamed:@"loader-9 (dragged).png"],
                                         [UIImage imageNamed:@"loader-10 (dragged).png"],
                                         [UIImage imageNamed:@"loader-11 (dragged).png"],
                                         [UIImage imageNamed:@"loader-12 (dragged).png"],
                                         [UIImage imageNamed:@"loader-13 (dragged).png"],
                                         [UIImage imageNamed:@"loader-14 (dragged).png"],
                                         [UIImage imageNamed:@"loader-15 (dragged).png"],
                                         [UIImage imageNamed:@"loader-16 (dragged).png"],
                                         [UIImage imageNamed:@"loader-17 (dragged).png"],
                                         [UIImage imageNamed:@"loader-18 (dragged).png"],
                                         [UIImage imageNamed:@"loader-19 (dragged).png"],
                                         [UIImage imageNamed:@"loader-20 (dragged).png"],
                                         [UIImage imageNamed:@"loader-21 (dragged).png"],
                                         [UIImage imageNamed:@"loader-22 (dragged).png"],
                                         [UIImage imageNamed:@"loader-23 (dragged).png"],
                                         [UIImage imageNamed:@"loader-24 (dragged).png"],
                                         [UIImage imageNamed:@"loader-25 (dragged).png"],
                                         [UIImage imageNamed:@"loader-26 (dragged).png"],
                                         [UIImage imageNamed:@"loader-27 (dragged).png"],
                                         [UIImage imageNamed:@"loader-28 (dragged).png"],
                                         [UIImage imageNamed:@"loader-29 (dragged).png"],
                                         [UIImage imageNamed:@"loader-30 (dragged).png"], nil];
    animatedImageView.animationDuration = 0.55f;
    animatedImageView.animationRepeatCount = 0;
    [animatedImageView startAnimating];
    [placeholderView addSubview:animatedImageView];
    [self.view insertSubview:placeholderView belowSubview:_tweetTable];
    self.placeholderView = placeholderView;

    _tweetTable.alpha = 0.0f;

}

1 个答案:

答案 0 :(得分:0)

原来我的帧速率太高(60 fps),这让iPhone做了太多工作。在30帧时将持续时间缩短到1.0f,将每秒帧数降低到30 fps,这解决了我的问题。