2016-07-27 121 views
0

进出口使用以下代码来的UIImageView动画显示不

UIImage* img1 = [UIImage imageNamed:@"1.gif"]; 
UIImage* img2 = [UIImage imageNamed:@"2.gif"]; 
UIImage* img3 = [UIImage imageNamed:@"3.gif"]; 
UIImage* img4 = [UIImage imageNamed:@"4.gif"]; 



UIView *loadingView = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/4, self.view.frame.size.height/4, 170, 170)]; 
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(65, 40, loadingView.bounds.size.width, loadingView.bounds.size.height)]; 
loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]; 
loadingView.clipsToBounds = YES; 
loadingView.layer.cornerRadius = 10.0; 
loadingView.center = self.view.center; 
imgView.backgroundColor = [UIColor clearColor]; 
imgView.center = loadingView.center; 
imgView.animationImages = @[img1, img2, img3, img4]; 
imgView.animationDuration = 1.0*1.0; 
[loadingView addSubview: imgView]; 
[self.view addSubview:loadingView]; 
[imgView startAnimating]; 
  1. 我已经定义了四个uiimages最初
  2. 的视图中居中的图像I所定义的loadingview,我已经它为中心,以屏幕
  3. 我已经定义了一个imageview,我已经将它集中到加载视图。
  4. 我已添加的ImageView是loadingView的子视图和我已经加入装载视图到view.Then IM动画化的ImageView

的问题是没有被示出的imaeview当我运行这码。我怎样才能解决这个问题?

+0

我想你'frame'是不正确的,因为其他的代码是正确的,由于错误的框架是不可见的,尝试调试。 – iphonic

+0

imgView.center = loadingView.center;是不正确的,并用这段代码正确的动画,你需要打破图像分开PNG/JPEG文件。 –

+1

使用SDWebImage设置GIF图像 – Birendra

回答

1

你好这里是代码

UIImage* img1 = [UIImage imageNamed:@"1.gif"]; 
UIImage* img2 = [UIImage imageNamed:@"2.gif"]; 

UIView *loadingView = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/4, self.view.frame.size.height/4, 170, 170)]; 
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 170, 170)]; 
loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]; 
loadingView.clipsToBounds = YES; 
loadingView.layer.cornerRadius = 10.0; 
loadingView.center = self.view.center; 
imgView.backgroundColor = [UIColor clearColor]; 
imgView.animationImages = @[img1, img2]; 
imgView.animationDuration = 1.0*1.0; 
[loadingView addSubview: imgView]; 
[imgView startAnimating]; 
[self.view addSubview:loadingView]; 
+3

你应该试着解释你有可能的话的原因一起做了什么样的变化。 –