2010-04-05 87 views
1

GIF圖片我已經找到了一些辦法,但它們實際上是閱讀框和應用過渡從而降低動畫的質量.. 有沒有辦法在iPhone上的應用程序顯示GIF,因爲它是...? 在此先感謝..如何顯示在iPhone上的UIImageView

+0

必須使用GIF?你可以使用一系列PNG嗎? – kennytm 2010-04-05 13:37:41

+0

你想顯示一個GIF動畫? – runmad 2010-04-05 13:37:49

回答

11

GIF動畫將無法運行動畫,但如果你有一個GIF,保存每個動畫作爲一個單獨的GIF,然後設置animationImages陣列與所有那些你剛剛保存的GIF:

UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds]; 
animatedImageView.animationImages = [NSArray arrayWithObjects:  
           [UIImage imageNamed:@"image1.gif"], 
           [UIImage imageNamed:@"image2.gif"], 
           [UIImage imageNamed:@"image3.gif"], 
           [UIImage imageNamed:@"image4.gif"], nil]; 
animatedImageView.animationDuration = 1.0f; 
animatedImageView.animationRepeatCount = 0; 
[animatedImageView startAnimating]; 
[self.view addSubview: animatedImageView]; 
0

使用網絡視圖。

if let path = Bundle.main.path(forResource: "animated", ofType: "gif") { 
     let url = URL(fileURLWithPath: path) 
     let request = URLRequest.init(url: url) 
     webview.loadRequest(request) 
    } 

這將呈現您的圖像並按預期設置動畫效果。