UIPopoverPresentationController

UIPopoverPresentationController

本文介绍了iOS 8 iPhone上的UIPopoverPresentationController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道是否可以使用 UIPopoverPresentationController 在iPhone上显示弹出窗口?想知道Apple是否在iOS 8上添加了此功能,试图为iPad和iPhone创建更统一的演示控制器。

Does anyone know if UIPopoverPresentationController can be used to present popovers on iPhones? Wondering if Apple added this feature on iOS 8 in their attempt to create a more unified presentation controllers for iPad and iPhone.

不确定是否可以向Beta提问/回答问题。在这种情况下,我将删除它。

Not sure if its OK to ask/answer questions from Beta. I will remove it in that case.

推荐答案

您可以覆盖默认的自适应行为( UIModalPresentationFullScreen 在紧凑的水平环境中,即iPhone)使用
adaptivePresentationStyleForPresentationController:方法可通过 UIPopoverPresentationController.delegate

You can override the default adaptive behaviour (UIModalPresentationFullScreen in compact horizontal environment, i.e. iPhone) using theadaptivePresentationStyleForPresentationController: method available through UIPopoverPresentationController.delegate.

UIPresentationController 使用此方法询问要使用的新演示样式,在您的情况下,只需返回 UIModalPresentationNone 将导致 UIPopoverPresentationController 呈现为弹出框而不是全屏。

UIPresentationController uses this method to ask the new presentation style to use, which in your case, simply returning UIModalPresentationNone will cause the UIPopoverPresentationController to render as a popover instead of fullscreen.

以下是使用故事板中的segue设置从 UIBarButtonItem 呈现模态a <$的popover示例c $ c> UIViewController

Here's an example of the popover using a segue setup in storyboard from a UIBarButtonItem to "present modally" a UIViewController

class SomeViewController: UIViewController, UIPopoverPresentationControllerDelegate {

    // override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { // swift < 3.0
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "PopoverSegue" {
            if let controller = segue.destinationViewController as? UIViewController {
                controller.popoverPresentationController.delegate = self
                controller.preferredContentSize = CGSize(width: 320, height: 186)
            }
        }
    }

    // MARK: UIPopoverPresentationControllerDelegate

    //func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!) -> UIModalPresentationStyle { // swift < 3.0
    func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
        // Return no adaptive presentation style, use default presentation behaviour
        return .None
    }
}

(36:30)

这篇关于iOS 8 iPhone上的UIPopoverPresentationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 21:58