【问题标题】:UIimage animation certain amountUIimage动画一定量
【发布时间】:2012-07-09 15:48:30
【问题描述】:

我正在 iOS 设备上创建一个应用程序,它会在背景上显示一个动画,但基本上我不希望您可以将多少图像上传到一个动画,这是我设置的代码。

.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
    IBOutlet UIImageView *animation;
}

@end

.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

-(void)viewDidLoad {



    animation.animationImages = [NSArray arrayWithObjects:

                                 [UIImage imageNamed:@"animatedbg1.gif"],

                                 [UIImage imageNamed:@"animatedbg2.gif"],

                                 [UIImage imageNamed:@"animatedbg3.gif"],

                                 [UIImage imageNamed:@"animatedbg4.gif"],

                                 [UIImage imageNamed:@"animatedbg5.gif"],

                                 [UIImage imageNamed:@"animatedbg6.gif"],

                                 [UIImage imageNamed:@"animatedbg7.gif"],

                                 [UIImage imageNamed:@"animatedbg8.gif"],

                                 [UIImage imageNamed:@"animatedbg9.gif"],nil],





    [animation setAnimationRepeatCount:0];

    animation.animationDuration = 2;

    [animation startAnimating];



} 

目前我有 9 张图片,但对于我的动画,我将有 155 张图片,所以这仍然有效 :) 如果没有,你们知道我可以采取更好的路线吗?

【问题讨论】:

    标签: ios animation uiimage xcode4.3 animated


    【解决方案1】:

    我认为您不会遇到任何严格的限制。但是,如果您使用太多图像,您可能会遇到内存限制。每张未压缩的图像有多大?这极大地影响了这一点。

    当然,您可能知道第 3 方 iOS 应用程序的可用内存量没有保证。根据系统上运行的其他内容、用户在 Mobile Safari 中打开的网页数量等,可用内存量不同。

    您可能需要构建它并进行试验。

    只是一个参考点。我有一个使用animationImages 的应用程序,图像不是全屏(480 x 270 像素)。这些图像是 24 位 PNG,每个大约 70KB,经过压缩。

    我发现我只能安全地使用其中的大约 10 个,而不必太担心会因为内存不足而被关闭。现在,当时我的目标是 iPhone 3G,它现在已经很老了。但是,您可能仍希望支持 iPhone 3G 机型。

    您当然可以query the device model in your code,并为您的应用尝试加载的图像数量设置不同的默认值。如果您想要更通用的东西,并且在新的 iOS 设备发布时不会中断,您可以ask the device about how much memory it has。然后,如果您检测到您在内存较少的设备上运行,您可以将您的应用程序编码为仅加载偶数编号的图像。

    您还可以在 UIViewControllers 中实现didReceiveMemoryWarning,并在收到内存警告时选择卸载一些图像。这一切都假设您的动画是这样的,即删除图像只会使动画看起来不那么流畅,并且不会使其完全不起作用。

    Here is some information on interpreting iOS memory warnings

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-11
      • 1970-01-01
      • 2014-05-06
      • 2020-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多