如何在iPhone中使用Popover控制器 [英] how to use popover controller in iPhone

查看:136
本文介绍了如何在iPhone中使用Popover控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将popover控制器显示为iPhone中的popover,但它在iPad上可以很好地工作.

I couldn't show popover controller as popover in iPhone whereas it works very well with iPad.

关于如何在iPhone中执行此操作的任何想法.

Any ideas on how to do that in iPhone.

据我搜索,我找不到任何东西.

As far as I have searched I couldn't find any.

无论如何要使弹出式窗口像在iPad中一样出现在iphone中!

anyways to make the popover appear in iphone as it is in iPad is appreciated !

推荐答案

在展示它之前,将自己设置为弹出视图控制器的委托 ,并实现委托方法adaptivePresentationStyle(for:traitCollection:)以返回.none.这将导致弹出式窗口停止在iPhone上作为全屏呈现的视图控制器进行调整,并变成实际的弹出式窗口,就像在iPad上一样.

Set yourself as the popover view controller's delegate before presenting it, and implement the delegate method adaptivePresentationStyle(for:traitCollection:) to return .none. This will cause the popover to stop adapting on iPhone as a fullscreen presented view controller and turn into an actual popover just like on the iPad.

这是一个完整的工作示例,它显示了响应于按钮轻击的弹出窗口:

This is a complete working example that presents the popover in response to a button tap:

class ViewController: UIViewController {
    @IBAction func doButton(_ sender: Any) {
        let vc = MyPopoverViewController()
        vc.preferredContentSize = CGSize(400,500)
        vc.modalPresentationStyle = .popover
        if let pres = vc.presentationController {
            pres.delegate = self
        }
        self.present(vc, animated: true)
        if let pop = vc.popoverPresentationController {
            pop.sourceView = (sender as! UIView)
            pop.sourceRect = (sender as! UIView).bounds
        }
    }
}
extension ViewController : UIPopoverPresentationControllerDelegate {
    func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
        return .none
    }
}

这篇关于如何在iPhone中使用Popover控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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