【问题标题】:Why popover does not have an arrow on iPhone?为什么popover在iPhone上没有箭头?
【发布时间】:2021-10-17 16:13:01
【问题描述】:

我在按下按钮时显示一个弹出框。 Popover 将其箭头指向按下的按钮:

UIViewController * controller = [self.storyboard instantiateViewControllerWithIdentifier: @"popover view"];
controller.modalPresentationStyle = UIModalPresentationPopover;
controller.popoverPresentationController.sourceView = button.imageView;

[self presentViewController: controller
                   animated: YES
                 completion: nil];

这是在故事板中定义弹出视图控制器的方式:

问题是在 iPhone 上这个弹出框是全屏绘制的,而在 iPad 和 Mac 上它是用指向按钮的箭头绘制的。我希望它总是有一个箭头。

我已经看到 iPhone 上的弹出框可以有箭头,但不能得到它。我错过了什么?为什么 iPhone popover 是全屏绘制且没有箭头?

【问题讨论】:

    标签: ios objective-c iphone popover


    【解决方案1】:

    您需要实现adaptivePresentationStyleForPresentationController:traitCollection: of UIPopoverPresentationControllerDelegate 并返回UIModalPresentationNone for popoverPresentationController delegate

    - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
                                                                   traitCollection:(UITraitCollection *)traitCollection
    {
        return UIModalPresentationNone;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-27
      • 1970-01-01
      • 2011-01-29
      相关资源
      最近更新 更多