ios8 - 是否可以强制 UIPopoverPresentationController 重新定位弹出框而不是调整其大小?

标签 ios8 autolayout uipopovercontroller uipopover uipresentationcontroller

我正在使用 Storyboard 的自动布局。我从单元格矩形中呈现一个 popoverPresentationController:

NumberController * viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"NumberController"];
UIPopoverPresentationController *pc = [viewController popoverPresentationController];
    pc.delegate = self;
    pc.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pc.sourceView = tableView;
    pc.sourceRect = [tableView rectForRowAtIndexPath:indexPath];
    [self.navigationController presentViewController:viewController animated:animated completion:nil];

弹出窗口以纵向模式显示在 iPad 上,且箭头向上。

我将 iPad 旋转为横向模式。 popoverPresentationController 保持相同的 sourceView/sourceRect 并正确指向单元格。它还保留了向上箭头。

但它现在位于 View 的底部,因此弹出窗口的大小调整为较短的高度。这不是我们想要的行为。

如果弹出窗口只是移动到新位置并更改箭头方向,则根本不需要调整大小。这是期望的行为。

我认为以下方法可能允许我进行更改,但它不会被调用,因为 sourceView 矩形不会更改:

- (void)popoverController:(UIPopoverController *)popoverController
willRepositionPopoverToRect:(inout CGRect *)rect
                   inView:(inout UIView **)view {

}

我尝试重置permissedArrowDirections(在preferredContentSize中,因为这似乎是最合乎逻辑的地方)。这不起作用(弹出窗口仍会调整大小):

- (CGSize) preferredContentSize {
    [super preferredContentSize];
    self.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUnknown;
    return CGSizeMake(DEFAULT_POPOVER_WIDTH,DEFAULT_POPOVER_HEIGHT);
}

我根本找不到一种方法来强制 popoverPresentationController 更改箭头方向并重新定位弹出框而不是调整弹出框的大小。我开始认为这甚至是不可能的 - 但我仍然抱有希望,我只是错过了一些东西。

编辑:与此同时,我突然想到,如果我不想在 iPad 中调整该 View 的大小,那么弹出窗口可能不是呈现此 View 的最佳方式。我将尝试使用 UIModalPresentationFormSheet 演示文稿。但我还是想找到这个问题的答案。

最佳答案

我刚刚遇到了问题

    - (void)popoverController:(UIPopoverController *)popoverController
    willRepositionPopoverToRect:(inout CGRect *)rect
               inView:(inout UIView **)view {

没有被调用,因为我的 View Controller 已分离。您的 View 层次结构中可能有一个 View ,其 View Controller 尚未添加为 subview Controller 。

I thought the following method might permit me to make changes, but it is not called since the sourceView rect does not change

sourceView 矩形不必改变,只需改变界面方向即可。来自 UIPopoverControllerDelegate 文档:

For popovers that were presented using the presentPopoverFromRect:inView:permittedArrowDirections:animated: method, the popover controller calls this method when the interface orientation changes.

关于ios8 - 是否可以强制 UIPopoverPresentationController 重新定位弹出框而不是调整其大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29307794/

相关文章:

ios - 在 iOS8 中选择/突出显示时 UITableViewCell 周围出现分隔线

autolayout - 在 Swift 中使用自动布局视觉格式?

ios - 自动布局 : Align two button side by side and move to right side when there is no image

ios - UIPopoverController 中的 UIWebView

ios - 使用完成按钮关闭弹出框或在弹出框上取消

ios - traitCollection.userInterfaceIdiom 返回 -1

iOS 8 : Can't use println in Custom Keyboard

ios - 与 UIActivityViewController 共享图像在 iOS 8 中为空白/损坏

objective-c - 在 iOS 8/Xcode 6 GM Seed 上使用自动布局调整大小时 UIScrollView 中断

swift - 关闭弹出窗口后表格 View 没有更新?