2016-07-27 62 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

你應該試着解釋你有可能的話的原因一起做了什麼樣的變化。 –