【问题标题】:Want to paste gif into mail window using UIPasteBoard想要使用 UIPasteBoard 将 gif 粘贴到邮件窗口中
【发布时间】:2011-10-22 09:18:37
【问题描述】:

我想展示一个 gif,所以我将我的 gif 拆分并使用此链接在 UIImageView 的动画中显示它。

http://iphonenativeapp.blogspot.com/2011/03/how-to-show-animation-in-iphoneipad-app.html

现在,我想让用户复制该 gif 并将其粘贴到邮件应用程序中。

如果我使用包含所有 gif 拆分图像的数组,那么 4-5 个图像会粘贴到邮件应用程序中。

请帮我粘贴 gif。谢谢!

【问题讨论】:

    标签: ios gif uipasteboard


    【解决方案1】:

    similar question 复制/粘贴我自己的答案。

    NSString *gifPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"volleyball.gif"];
    NSData *gifData = [[NSData alloc] initWithContentsOfFile:gifPath];
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    [pasteboard setData:gifData forPasteboardType:@"com.compuserve.gif"];
    [gifData release];
    

    编辑刚刚注意到您自己问了这两个类似的问题。

    【讨论】:

    • 非常感谢!!!!它现在工作。实际上我昨天尝试过这个东西,但它不起作用,因为我在 forPasteboardType 部分搞砸了。我变得如此绝望,我再次发布了它......顺便说一句,你能告诉我什么是“com.compuserve.gif”吗????或者应该使用什么作为“forPasteboardType”的参数?????
    【解决方案2】:

    虽然您可以使用基于 HTML 的电子邮件——例如:

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    NSString *emailBody = @"<p><b>Hello World</b></p>";                         
    [picker setMessageBody:emailBody isHTML:YES];
    

    您不能像在 HTML 中那样插入内嵌图像。 HTML 电子邮件中的内嵌图像使用单独的 MIME 部分,这些部分通过邮件正文中的 content-id 元素引用。 MFMailComposeViewController 不能让您控制消息的 MIME 结构,因此不允许您添加内联引用的内容部分。

    将图像数据作为 base64 嵌入&lt;img&gt; 标记有时会起作用——这取决于用于呈现它的电子邮件客户端和浏览器——但它的可移植性并不大。

    【讨论】:

      【解决方案3】:

      FWIW,动画 gif 似乎可以在 iOS 6 的新共享表中与电子邮件一起使用,如果用户选择邮件,它将自动在电子邮件中填充 gif:

      NSString *gifPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"volleyball.gif"];
      NSData *gifData = [[NSData alloc] initWithContentsOfFile:gifPath];
      NSArray *activityItems = [NSArray arrayWithObjects:@"Here is an awesome body for the email.",gifData,nil];
      UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
      activityController.completionHandler = ^(NSString *activityType, BOOL completed){
        // item was shared!
        // you can check if it was email (or another type, like facebook or twitter) in the *activityType.
        // completed is YES if they actually shared it, if they canceled, completed will be NO.
      };
      [navigationController presentViewController:activityController animated:YES completion:nil];
      

      【讨论】:

        【解决方案4】:

        由于 iOS 不支持动画 GIF 格式,我认为无法在邮件应用程序中复制/粘贴 gif。但是,您可以尝试附加 gif 文件(而不是拆分图像)并使用 MFMailComposeViewController 撰写新电子邮件。如果您在非 iOS 设备上打开附件,您应该能够看到动画 GIF。

        HTH,

        阿克谢

        【讨论】:

        • 不,我在 iphone 的 safari 浏览器中尝试过。我打开了一个包含 gif 的 URL,将其复制并粘贴到邮件窗口中。它工作正常。所以,应该也可以正常复制gif!
        • 在这种情况下,您应该将 gif 文件粘贴到 UIPasteBoard 上,而不是分割图像的数组。您必须了解如何允许用户复制 gif,例如通过提供复制按钮或在用户长按 UIImageView 时添加自定义 UIMenuItem。
        猜你喜欢
        • 2012-02-25
        • 1970-01-01
        • 1970-01-01
        • 2018-01-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-23
        • 2019-06-06
        相关资源
        最近更新 更多