[英]iOS UIImageView not animating
我正在制作一个应用程序,并具有一个IBAction,该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;
}
看到,直到从该URL加载另一个图像并且不进行动画处理为止,ImageView activityImageView才会显示。 有人看到可能导致此问题的任何问题吗?
我假设您使用的是+[UIImage animatedImageWithAnimatedGIFURL:duration:]
。
此方法是同步的。 直到从URL加载了所有数据后,它才会返回。 因此,当您在主线程上调用它时,就阻塞了主线程,从而阻止了其他动画的启动(并防止了任何用户交互)。
可以使用+[NSURLConnection connectionWithRequest:delegate:]
或+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]
而不是+[UIImage animatedImageWithAnimatedGIFURL:duration:]
+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]
来从后台URL中加载数据。 加载+[UIImage animatedImageWithAnimatedGIFData:duration:]
后,请使用+[UIImage animatedImageWithAnimatedGIFData:duration:]
创建图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.