【问题标题】:UIDocumentInteractionController not appearing on iPad but working on iPhoneUIDocumentInteractionController 未出现在 iPad 上但在 iPhone 上工作
【发布时间】:2013-08-08 03:03:01
【问题描述】:

我正在尝试在我的应用上显示UIDocumentInteractionController。在 iPhone 上一切正常,但在 iPad 上却什么也没有。这是我的代码:

    interactionController = [UIDocumentInteractionController interactionControllerWithURL:imageFile];
    interactionController.UTI = @"com.instagram.photo";
    interactionController.annotation = [NSDictionary dictionaryWithObject:[self commentForInstagram] forKey:@"InstagramCaption"];
    [interactionController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES];

interactionController 是对实例的强引用,imageFile 存在。在 iPhone 上,它会弹出“打开方式...”对话框,并且 Instagram 存在。在 iPad 上,上述代码运行时绝对没有任何反应。是的,我确实安装了 Instagram,并且可以在我的 iPad 上使用。

执行代码时什么都没有发生的原因可能是什么? self.viewself.view.frame 是有效对象(在调试时测试)。

谢谢,坎。

【问题讨论】:

  • 调用presentOpenInMenuFromRect:inView:animated:的返回值是多少?您确定 imageFile 不是 nil 并且是指向图像文件的有效文件 URL?
  • 正如我在问题中明确指出的那样, imageFile 存在。问题似乎源于目前的方法以及它在 iPhone 和 iPad 上的行为方式有何不同。如果我传入一个自定义矩形,并将 self.view.windows 作为视图,它似乎确实有效。

标签: ios ipad ios6 uidocumentinteraction


【解决方案1】:

presentOptionsMenuFromRect:inView: - 这是关于弹出框箭头指向的位置。

view是箭头所指的view,rect是view内箭头所指的rect

一旦你明白这很容易。

- (void)shareClick:(UIButton*)sender
{
   /*some code*/
   [interactionController presentOptionsMenuFromRect:sender.bounds inView:sender animated:YES];
}

所以现在箭头将指向按钮边界的边缘。

大多数时候这是您想要的,但您可以例如插入此矩形以使箭头位于按钮内。

【讨论】:

    【解决方案2】:

    我有同样的问题。我检查了正在传递的帧,发现 x 和 y 设置为 0。接下来我尝试更改这些值(通过保持传递的宽度和高度)并且弹出窗口出现了。代码如下:

    -(void)openDocument:(UIView*)senderView {
    
       CGRect rectForAppearing = [senderView convertRect:senderView.frame toView:senderView];
    
       if (isIPAD)
         rectForAppearing =  CGRectMake(100, 100, rectForAppearing.size.width, rectForAppearing.size.height);
    
       [interactionController presentOptionsMenuFromRect:rect inView:self.view animated:YES];
    

    }

    弹出窗口出现在右上角的 Ipad 上。您当然可以根据自己的意愿扭曲这 100,100 个参数。在 iPhone 上,我将弹出框保持原样(在底部)

    【讨论】:

      【解决方案3】:

      我今天早些时候遇到了同样的问题。

      首先,不要将视图的frame 传递给presentOptionsMenuFromRect:inView:animated。给定的矩形应该在视图的坐标中。视图的frame 在视图的父视图的坐标中。

      在 iPhone 上,传递视图的 bounds 有效,但在 iPad 上,Xcode (7.2.1) 会抱怨不可满足的约束并且不显示文档交互控制器的视图 (DIC)。

      而不是bounds,我尝试传递CGRectZero 作为第一个参数,它将DIC 锚定在视图的左上角。这可行,但看起来很糟糕。

      为了将 DIC 定位在视图底部边缘的中心,您可以指定位于视图底部边缘中心的大小为 CGSizeZero 的矩形(使用视图的 bounds 来计算位置)。这行得通,看起来还不错。

      【讨论】:

        【解决方案4】:

        对于 iPad,您必须满足以下两点:

        1. 为 DocumentActionMenu 定义区域

          CGRect 矩形 = CGRectMake(0.0, 0.0, 0.0, 0.0);

          [interactionController presentOpenInMenuFromRect:rect inView:self.view animated:YES];

        2. 使用 iPad,而不是模拟器

        【讨论】:

        • 谢谢。仅供参考,可以使用 CGRectZero 而不是创建一个新的。
        【解决方案5】:

        使用presentOptionsMenuFromRect:inView:animated:

        例如,如果您希望菜单从底部呈现,请尝试

        [interactionController presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];
        

        【讨论】:

          【解决方案6】:

          在 iPad 上 UIDocumentInteractionController 看起来像 Pop Up 试试这样的:

          -(void)shareClick:(UIButton*)sender {
             /*some code*/
             CGRect rectForAppearing = [sender.superview convertRect:sender.frame toView:self.view];
             [interactionController presentOptionsMenuFromRect:rect inView:self.view animated:YES];
          }
          

          【讨论】:

            猜你喜欢
            • 2012-01-22
            • 2016-10-17
            • 2016-07-07
            • 1970-01-01
            • 2011-05-01
            • 2015-03-17
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多