0

我正在尝试从一些 URLS 制作动画。

我知道代码

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];

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

4

1 回答 1

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];

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

于 2013-04-26T16:19:29.237 回答