来自URLS的Xcode动画而不是本地文件

时间:2012-11-12 22:44:43

标签: xcode image url animation imageview

我正在尝试从某些网址制作动画。

我知道代码

animation.animationImages = [NSArray arrayWithObjects:
                             [UIImage imageNamed:@"img-1.gif"],
                             [UIImage imageNamed:@"img-2.gif"],
                             [UIImage imageNamed:@"img-3.gif"],
                             [UIImage imageNamed:@"img-4.gif"],nil];
[animation setAnimationRepeatCount:3];
animation.animationDuration = 2;
[animation startAnimating];

但是如何从服务器加载多张图片并使其具有动画效果? 我有一个名为动画的图像视图 任何人都可以帮我解决一个例子吗?

1 个答案:

答案 0 :(得分:0)

这里'我使用的是我的

我用我的viewDidLoad方法

做了我的
//use your URL
NSData *picOne = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://sumptin.com/images/sumptin.jpg"]];
NSData *picTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://sumptin.com/images/sumptin.jpg"]];
NSData *picThree = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://sumptin.com/images/sumptin.jpg"]];
NSData *picFour = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://sumptin.com/images/sumptin.jpg"]];
NSData *picFive = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://sumptin.com/images/sumptin.jpg"]];

//then convert data to actual pictures  
UIImage *onePic = [UIImage imageWithData:picOne];
UIImage *twoPic = [UIImage imageWithData:picTwo];
UIImage *threePic = [UIImage imageWithData:picThree];
UIImage *fourPic = [UIImage imageWithData:picFour];
UIImage *fivePic = [UIImage imageWithData:picFive];

//then SHABAM!
 slideShow.animationImages = [NSArray arrayWithObjects:
                             onePic,
                             twoPic,
                             threePic,
                             fourPic,
                             fivePic,
                             nil];
slideShow.animationDuration = 60.00f;
slideShow.animationRepeatCount = 0;

[slideShow startAnimating];

希望这有助于...看到这个问题是在一年前发布的:)