这是我在 StackOverflow 上的第一个问题,所以请耐心等待我......
这就是问题所在:
我创建了一个用于添加书签的自定义 Activity,它是从UIActivityViewController
. 在 iPhone 上,它作为模态打开,这没关系。但是在 iPad 上,我UIActivity
在 Popover 中打开,并且我希望自定义 BookmarkActivity 也可以在此 Popover 中打开。
方法
-(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 以模态方式呈现在 iPad 上而不是 popover
- [UIActivity activityViewController] is not present in a UIPopoverController
他们俩都建议,目前不可能,但不知何故它一定是可能的——它在 Safari 中有效(也是“添加书签”功能)。
所以问题是:
- 如何正确更改要在弹出窗口中打开的自定义视图控制器的这种行为?
- 如果目前唯一的可能性是将其作为普通弹出窗口打开,有没有办法调整它的大小?我尝试更改导航控制器和书签控制器的大小和框架,但它不起作用。
编辑:我已就此与 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];
}
}