在常规尺寸的iPhone上与UIPopoverPresentationController的内容进行交互? [英] Interacting with contents of UIPopoverPresentationController on regular sized iPhones?

查看:69
本文介绍了在常规尺寸的iPhone上与UIPopoverPresentationController的内容进行交互?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎-至少默认情况下,您可以在plus iPhone上与弹出窗口的内容进行交互,并通过在常规的非plus手机上点击背景来将其关闭,行为却是相反的.

有人知道如何更正和/或配置它,以便您可以与普通iPhone上的弹出窗口进行交互吗?

我有一个示例可以在这里演示问题:
https://github.com/chrisco314/iPhone-Popover-Test

但相关代码为:

  class PresentingViewController:UIViewController {覆盖func viewDidLoad(){super.viewDidLoad()配置()}func configure(){view.addSubview(button)view.backgroundColor = .whitebutton.centerXAnchor.constraint(equalTo:view.centerXAnchor).isActive = truebutton.topAnchor.constraint(等于:view.topAnchor,常数:50).isActive = true}懒惰的var按钮:UIButton = {让按钮= UIButton()button.layer.cornerRadius = 10button.contentEdgeInsets = .init(顶部:8,左侧:8,底部:8,右侧:8)button.backgroundColor = .bluebutton.setTitle(显示弹出窗口",用于:.normal)button.addTarget(self,action:#selector(didTap(sender :)),for:.touchUpInside)button.translatesAutoresizingMaskIntoConstraints = false返回按钮}()覆盖func didReceiveMemoryWarning(){super.didReceiveMemoryWarning()//处理所有可以重新创建的资源.}@objc func didTap(sender:UIButton){让present = PresentedViewController()present.modalPresentationStyle = .popover让popover = present.popoverPresentationController!popover.delegate =自我popover.sourceRect = sender.boundspopover.sourceView =发送者popover.permittedArrowDirections = .uppopover.backgroundColor = popover.presentedViewController.view.backgroundColorself.present(呈现,动画:true,完成:{})}}扩展PresentingViewController:UIPopoverPresentationControllerDelegate {funcadaptivePresentationStyle(用于控制器:UIPresentationController)->UIModalPresentationStyle {返回.none}}类PresentedViewController:UIViewController {覆盖func viewDidLoad(){super.viewDidLoad()配置()}func configure(){view.backgroundColor = .greenview.addSubview(文本)text.leftAnchor.constraint(equalTo:view.leftAnchor,常数:20).isActive = trueview.rightAnchor.constraint(equalTo:text.rightAnchor,常数:20).isActive = truetext.topAnchor.constraint(等于:view.topAnchor,常数:50).isActive = trueview.bottomAnchor.constraint(greaterThanOrEqualTo:text.bottomAnchor,常数:50).isActive = true}惰性文本:UITextField = {让view = UITextField()view.text =占位符"view.translatesAutoresizingMaskIntoConstraints = falseview.backgroundColor = .blue返回视图}()} 

谢谢!

解决方案

我现在正在考虑这可能是模拟器问题.我在自己的主要项目中看到了一个单独的样本,然后编写了一个新的更清洁的样本供公众使用.然后,我在不同版本的模拟器之间来回切换,然后它再次开始工作.

很奇怪.

It appears - at least by default, that while you can interact with the contents of a popover on a plus iPhone and dismiss it by tapping on the background, on a regular, non plus phone, the behavior is the opposite.

Does anyone know how to correct and/or configure this so that you can interact with a popover on an regular iPhone?

I have a sample that demonstrates the problem here:
https://github.com/chrisco314/iPhone-Popover-Test,

but the relevant code is:

class PresentingViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        configure()
    }

    func configure() {
        view.addSubview(button)
        view.backgroundColor = .white
        button.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        button.topAnchor.constraint(equalTo: view.topAnchor, constant: 50).isActive = true
    }

    lazy var button: UIButton = {
        let button = UIButton()
        button.layer.cornerRadius = 10
        button.contentEdgeInsets = .init(top: 8, left: 8, bottom: 8, right: 8)
        button.backgroundColor = .blue
        button.setTitle("Show popover", for: .normal)
        button.addTarget(self, action: #selector(didTap(sender:)), for: .touchUpInside)
        button.translatesAutoresizingMaskIntoConstraints = false
        return button
    }()

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @objc func didTap(sender: UIButton) {
        let presented = PresentedViewController()
        presented.modalPresentationStyle = .popover

        let popover = presented.popoverPresentationController!
        popover.delegate = self
        popover.sourceRect = sender.bounds
        popover.sourceView = sender
        popover.permittedArrowDirections = .up
        popover.backgroundColor = popover.presentedViewController.view.backgroundColor

        self.present(presented, animated: true, completion: {})
    }
}

extension PresentingViewController: UIPopoverPresentationControllerDelegate {

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


class PresentedViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        configure()
    }

    func configure() {
        view.backgroundColor = .green
        view.addSubview(text)
        text.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 20).isActive = true
        view.rightAnchor.constraint(equalTo: text.rightAnchor, constant: 20).isActive = true
        text.topAnchor.constraint(equalTo: view.topAnchor, constant: 50).isActive = true
        view.bottomAnchor.constraint(greaterThanOrEqualTo: text.bottomAnchor, constant: 50).isActive = true
    }

    lazy var text: UITextField = {
        let view = UITextField()
        view.text = "Placeholder"
        view.translatesAutoresizingMaskIntoConstraints = false
        view.backgroundColor = .blue
        return view
    }()
}

Thanks!

解决方案

I am thinking now that this might have been a simulator problem. I had seen this on my main project, a separate sample, and then wrote a new cleaner sample for public consumption. I then switched back and forth between different versions of the simulator and it started working again.

Weird.

这篇关于在常规尺寸的iPhone上与UIPopoverPresentationController的内容进行交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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