我正在创建一个应用程序,并且当用户点击按钮时会触发一个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加载另一个图像并且不是动画时才会显示。有人看到可能造成这种问题的任何问题吗?
答案 0 :(得分:1)
我假设您使用的是my implementation of +[UIImage animatedImageWithAnimatedGIFURL:duration:]
。
此方法是同步的。在加载了URL中的所有数据之前,它不会返回。因此,当您在主线程上调用它时,您将阻止主线程,从而阻止您的其他动画启动(并阻止任何用户交互)。
不使用+[UIImage animatedImageWithAnimatedGIFURL:duration:]
,而是使用+[NSURLConnection connectionWithRequest:delegate:]
或+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]
在后台加载来自网址的数据。当它全部加载完毕后,使用+[UIImage animatedImageWithAnimatedGIFData:duration:]
创建图像。