iOS 7自定义UIActivity为popover

时间:2014-05-12 13:59:41

标签: ios ipad popover uiactivity


这是关于StackOverflow的第一个问题,所以请耐心等待我......

问题在于:
我已经创建了一个用于添加书签的自定义活动,该活动是从UIActivityViewController打开的。在iPhone上,它作为模态打开,这没关系。但是在iPad上我打开了Popover中的UIActivity,我也想在这个Popover中打开自定义BookmarkActivity。
方法

我的-(UIViewController *)activityViewController子类中的

UIActivity如下所示:

- (UIViewController *)activityViewController {

    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        GlobalBookmarksAddViewController *bookmarkViewController = [self.parentController.storyboard instantiateViewControllerWithIdentifier:@"GlobalBookmarksAddViewController"];

        bookmarkViewController.openedDocument = self.openedDocument;
        bookmarkViewController.yAxis = self.yAxis;
        bookmarkViewController.parentActivity = self;

        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:bookmarkViewController];

        nav.modalInPopover = YES;
        //nav.modalPresentationStyle = UIModalPresentationFormSheet;
        nav.modalPresentationStyle = UIModalPresentationCurrentContext;

        return nav;
    } else {
        GlobalBookmarksAddViewController *bookmarkViewController = [self.parentController.storyboard instantiateViewControllerWithIdentifier:@"GlobalBookmarksAddViewController"];

        bookmarkViewController.openedDocument = self.openedDocument;
        bookmarkViewController.yAxis = self.yAxis;
        bookmarkViewController.parentActivity = self;

        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:bookmarkViewController];

        return nav;
    }
}

使用此代码,书签控制器在弹出框中显示约0.2秒,然后弹出消失。如果我将属性nav.modalPresentationStyle UIModalPresentationCurrentContext 更改为 UIModalPresentationFormSheet ,则会正确显示bookmarkController,但是会以正常的弹出窗口显示。

我已经做了一些研究,我找到了两个链接:
UIActivity activityViewController being presented modally on iPad instead of in popover
-[UIActivity activityViewController] is not presented in a UIPopoverController

他们俩都建议,目前不可能,但不知何故,它必须是可行的 - 它适用于Safari(也是#34;添加书签"功能)。

所以问题是:

  1. 如何更改要在popover中正确打开的自定义视图控制器的此行为?
  2. 如果目前唯一的可能性是将其作为普通弹出窗口打开,有没有办法调整它?我曾尝试更改导航控制器和书签控制器的大小和框架,但它不起作用。
  3. 编辑:我已就此问与Apple联系,以下是解决方案:
    方法-(UIViewContreoller *)activityController现在看起来像这样:

    -(UIViewController *)activityViewController
    {
        if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
        {
            return nil;
        }
        else
        {
            GlobalBookmarksAddViewController *bookmarkViewController = [self.parentController.storyboard instantiateViewControllerWithIdentifier:@"GlobalBookmarksAddViewController"];
    
            bookmarkViewController.openedDocument = self.openedDocument;
            bookmarkViewController.yAxis = self.yAxis;
    
            bookmarkViewController.parentActivity = self;
    
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:bookmarkViewController];
    
            return nav;
        }
    }
    

    并且popover中的视图代码已移至-(void)performActivity方法:

    -(void)performActivity
    {
         if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
        {
            GlobalBookmarksAddViewController *bookmarkViewController = [self.parentController.storyboard instantiateViewControllerWithIdentifier:@"GlobalBookmarksAddViewController"];
    
            bookmarkViewController.openedDocument = self.openedDocument;
            bookmarkViewController.yAxis = self.yAxis;
    
            bookmarkViewController.parentActivity = self;
    
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:bookmarkViewController];
    
            nav.modalInPopover = YES;
            nav.modalPresentationStyle = UIModalPresentationCurrentContext;
    
            // self.activityController is my own property set for the activity after the UIActivityViewController is created
            [self.activityController presentViewController:nav animated:YES completion:NULL];
        }
    }
    

0 个答案:

没有答案