UIPopoverPresentationController将popover显示为全屏 [英] UIPopoverPresentationController displaying popover as full screen

查看:234
本文介绍了UIPopoverPresentationController将popover显示为全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 UIPopoverPresentationController 来显示不占用整个屏幕的 popover 。我已经遵循了许多不同的教程而没有运气。

I am trying to use UIPopoverPresentationController to display a popover that doesn't take up the whole screen. I've followed many different tutorials with no luck.

这是我的代码。它正确地实例化 ViewController ,但它占用了整个屏幕,而不是像我在 preferredContentSize 中定义的那样小屏幕。

Here is my code. It correctly instantiates the ViewController, but it takes up the entire screen instead of just a smaller screen as I defined in preferredContentSize.

func showPopover() {
    let vc = self.storyboard?.instantiateViewControllerWithIdentifier("PopupTimePickerViewController") as PopupTimePickerViewController
    vc.modalPresentationStyle = .Popover
    vc.preferredContentSize = CGSizeMake(200, 100)

    if let presentationController = vc.popoverPresentationController {
        presentationController.delegate = self
        presentationController.permittedArrowDirections = .Up
        presentationController.sourceView = self.view
        presentationController.sourceRect = CGRectMake(0, 0, 50, 50)

        self.presentViewController(vc, animated: true, completion: nil)
    }
}

更新9/27/16,回答正确

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
    return .none
}


推荐答案

在iPhone中,你应该添加以下内容以呈现一个弹出窗口。

In iPhone, you should add the following in order to present a popover.

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

这篇关于UIPopoverPresentationController将popover显示为全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆