2014-10-29 72 views
1

我沒有得到有關使用UIActivityViewController.please幫我解決this.thanks提前如何共享一個GIF動畫圖片中的iOS

see this image .i am displaying this type of images and to share these images I am using uiactivity view but it is not animating .it's just displaying image 



if(imgFrameCount==1) 

    { 
     imgFrameCount++; 
     NSURL *url1=[[NSBundle mainBundle]URLForResource:@"animated2" withExtension:@"gif"]; 
     self.firstImage=[UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url1]]; 
     self.frameImage.image = self.firstImage; 
    } 
else if (imgFrameCount==2) 
{ 
    imgFrameCount++; 
    NSURL *url2=[[NSBundle mainBundle]URLForResource:@"animated3" withExtension:@"gif"]; 
    self.firstImage=[UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url2]]; 
    self.frameImage.image = self.firstImage; 
} 
+0

你是什麼意思**共享gif圖像**?請指定並提供代碼和/或屏幕截圖。 – 2014-10-29 06:54:18

+0

請回復我,我們是否可以使用uiactivity查看分享gif動畫圖片 – Suneha 2014-10-29 07:32:09

+0

我已分享gif動畫圖片,請檢查它。 – Suneha 2014-10-29 07:41:46

回答

1

嘗試使用此代碼共享的.gif動畫圖像的任何想法。

NSArray *animeImages = [NSArray arrayWithObjects: 
            [UIImage imageNamed:@"tmp-0.png"], 
            [UIImage imageNamed:@"tmp-1.png"], 
            [UIImage imageNamed:@"tmp-2.png"], 
            [UIImage imageNamed:@"tmp-3.png"], 
            [UIImage imageNamed:@"tmp-4.png"], 
            [UIImage imageNamed:@"tmp-5.png"], 
            [UIImage imageNamed:@"tmp-6.png"], 
            [UIImage imageNamed:@"tmp-7.png"], 
            [UIImage imageNamed:@"tmp-8.png"], 
            [UIImage imageNamed:@"tmp-9.png"], 
            [UIImage imageNamed:@"tmp-10.png"], 
            [UIImage imageNamed:@"tmp-11.png"], 
            nil]; 
imageView.image = [UIImage animatedImageWithImages:animeImages duration:2.0]; 

您現在可以玩這個的ImageView,並設置其各種屬性像架和隱藏等,使它像一個活動指示燈工作。在數組中傳遞的圖像是動畫gif的細分。它可以很容易地使用任何在線工具,如this one

+0

看到這個網址... http://i.stack.imgur.com/YkGe1.gif謝謝我已經完成了編碼顯示images.actually我有.gif圖像.. 。 – Suneha 2014-10-29 12:37:03

+0

我使用直接.gif圖像來顯示,並顯示正常,但我的問題是我們如何分享這些.gif圖像。 – Suneha 2014-10-29 12:40:34

+0

**分享**是什麼意思?並且請發佈代碼以在iOS中直接顯示動畫GIF。我一直在尋找,但沒有找到一個潛在的解決方案。 – 2014-10-29 12:54:44

6

FWIW,我試圖將一個UIImage包含在ActivityItems數組中時遇到了同樣的問題。它不會使用通用UIImage,也不會使用UIImage + animagedGIF類別和FLAnimatedImage。

要解決此問題,至少在iOS8上,只需將gif添加到ActivityItems數組中作爲NSData對象而不是UIImage。

例如,假設GIF正在從URL請求:

NSURL *imagePath = [NSURL URLWithString:@"http://i.imgur.com/X4oonnm.gif"]; 
NSData *animatedGif = [NSData dataWithContentsOfURL:imagePath]; 
NSArray *sharingItems = [NSArray arrayWithObjects: animatedGif, nil]; 

UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil]; 
+1

其中是photData定義? – AlexKoren 2015-07-09 20:34:03

+0

@AlexKoren,對不起。這是一個NSDictionary的引用,其中包含我想包含在ActivityViewController中的額外信息(如圖像標題,標題和url) 我更新了示例以將其刪除,因爲在提供工作解決方案時沒有必要 – 2016-06-19 22:55:21

0

這應該這樣做。擴大約旦Bonitatis的答案。訣竅是創建一個NSData對象,其內容爲NSURL

- (void)share 
{ 
    NSURL *imageURL = [NSURL URLWithString:@"http://...url..of..gif]; 
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; 
    NSArray *objectsToShare = @[imageData]; 

    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; 

    NSArray *excludeActivities = @[UIActivityTypeAirDrop, 
           UIActivityTypePrint, 
           UIActivityTypePostToVimeo]; 

    activityVC.excludedActivityTypes = excludeActivities; 

    [self presentViewController:activityVC animated:YES completion:nil]; 
} 
+0

這不起作用。它顯示了一個靜態圖片,儘管一個gif的URL。 – scientiffic 2016-05-11 13:49:12

2

這是一個棘手的問題,因爲不同的共享接收器處理數據的方式不同。因此,在其他答案中提到的NSData解決方案在共享給幾個不同的應用程序時確實有效,但對於大多數應用程序來說並不適用看起來,接收器需要足夠聰明來解碼字節數組,並確定它確實是一個動畫gif,但大多數不這樣做。一個更好的計劃似乎是發送帶有適當擴展名的文件引用,因爲大多數應用程序都會識別文件擴展名。所以我目前的策略是從https://stackoverflow.com/a/13028336/158770中取出,但寫入名爲「share.gif」或類似文件。當以這種方式分享時,幾乎所有可以處理動畫gif的應用程序都能夠正確接收。