这是关于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;添加书签"功能)。
所以问题是:
编辑:我已就此问与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];
}
}