0

我正在制作一个应用程序并有一个当用户点击按钮时触发的 IBAction。继承人的代码:

- (IBAction)expand:(id)sender{
UIImage *statusImage = [UIImage imageNamed:@"status.png"];
[activityImageView setImage:statusImage];

CATransform3D rotationTransform = CATransform3DMakeRotation(1.0f * M_PI, 0, 0, 1.0);
CABasicAnimation* rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];

rotationAnimation.toValue = [NSValue valueWithCATransform3D:rotationTransform];
rotationAnimation.duration = 0.25f;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 1;

[activityImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
[[NSUserDefaults standardUserDefaults]setFloat:self.conditionsImageView.bounds.size.height forKey:@"rect"];
[[NSUserDefaults standardUserDefaults]setFloat:self.conditionsImageView.bounds.origin.y forKey:@"y"];
NSURL *uuu = [NSURL URLWithString:@"http://api.wunderground.com/api/3c158b3b3cd6ce90/animatedradar/q/autoip.gif?newmaps=1&timelabel=1&smooth=1&timelabel.y=10&num=8&delay=50&width=640&height=960"];
self.conditionsImage = [UIImage animatedImageWithAnimatedGIFURL:uuu duration:8];
self.conditionsImageView.bounds = CGRectMake(0, 0, 320, self.view.bounds.size.height + 20);
self.conditionsImageView.image = conditionsImage;
exp.hidden = 0;
exp1.hidden = 1;


}

看,ImageView activityImageView 不会显示,直到从该 url 加载另一个图像完成并且它没有动画。有人看到任何可能导致此问题的问题吗?

4

1 回答 1

1

我假设您正在使用我的+[UIImage animatedImageWithAnimatedGIFURL:duration:].

这种方法是同步的。在从 URL 加载所有数据之前,它不会返回。因此,当您在主线程上调用它时,您将阻塞主线程,从而阻止您的其他动画启动(并阻止任何用户交互)。

而不是使用+[UIImage animatedImageWithAnimatedGIFURL:duration:],使用+[NSURLConnection connectionWithRequest:delegate:]+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]在后台从 URL 加载数据。当它全部加载后,然后用于+[UIImage animatedImageWithAnimatedGIFData:duration:]创建图像。

于 2013-01-30T03:54:41.183 回答