ios13 UIPopoverViewController显示UITableViewController-安全区域问题/表的缺失部分 [英] ios13 UIPopoverViewController showing UITableViewController - Safe Area problems / Missing parts of table

查看:99
本文介绍了ios13 UIPopoverViewController显示UITableViewController-安全区域问题/表的缺失部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与这篇文章相同的主题:

In the same theme as this post:

iOS 13- UIPopoverPresentationController源视图内容在箭头中可见

我有一个从Storyboard实例化的UITableViewController.我正在UIPopoverViewController中展示它.

I have a UITableViewController instantiated from the Storyboard. I'm presenting it in a UIPopoverViewController.

根据方向,我要么缺少侧面,要么缺少顶部,并且_UITableViewHeaderFooterViewBackground的内容在箭头"中滚动.

Depending on orientation I either have a side missing or the top missing and the content of the _UITableViewHeaderFooterViewBackground scrolls 'through' the arrow.

怎么了:

这些是当它在顶部时,但是如果它出现在侧面,则整个侧面

These are when it's on the top, but if it presents on the side then the whole side

我正在使用安全区域指南:

I AM using the Safe Area Guides:

正如我之前说的,我从对象库中拖动了一个全新的UITVC,然后将原型单元更改为我的应用程序要求.

As I said previously, I dragged on from the object library a brand new UITVC and then changed the prototype cell to my app's requirements.

我对任何安全区域的拨码或设置都进行了零更改.

I made zero changes to any safe area toggles or settings.

我不会更改代码中的任何安全区域插图或调整内容.

I do not change any safe area insets or adjustments in code.

所以,谢谢@Alex,但这不是问题所在,或者如果不是,我不知道该怎么办.

So, thank you @Alex, but that's not the problem, or if it is, I don't know what to do about it.

今天下午,我确保我的班级中的代码为零,可以进行任何格式,颜色,插入或任何与更改默认表单元格形式有关的操作.

This afternoon, I made sure I have zero code in my classes that do any formatting, colours, inserts, or ANYTHING to do with ANY form of changing default table cells.

然后我在IB中完全删除了我的UITVC,并创建了一个新的UITVC,创建了没有样式的新原型单元,只是将UIImageView放置在该单元中.

I then completely deleted my UITVC in IB and created a new one, create new prototype cell with no styling except to put a UIImageView in the cell.

我确保UITVC,tableviewcell和内容视图在IB中都勾选了安全区域"和安全边距".

I ensured the UITVC, the tableviewcell and content view all has 'Safe Area' and 'Safe Margins' ticked in IB.

重建应用程序并运行.

完全一样.

我仍然在箭头上看到内容和背景,如果再在表格周围添加边框,则表示侧将被切除".

I still have both content and background going over the arrow and if I then add a border around the table the presenting side is 'cut off'.

我知道问题是什么!!

I KNOW WHAT THE PROBLEM IS!!!

是_UITableViewHeaderFooterViewBackground与AutoLayout搭配使用效果不佳!

It's the _UITableViewHeaderFooterViewBackground that doesn't play nicely with AutoLayout!!

我不确定如何解决它,但这就是问题所在.

I'm not sure how to fix it, but that's what the problem is.

编辑4/更新:

今天,我构建了以下应用程序,并且该bug仍然存在-即使没有科目标题!

Today I built the following app, and the bug is still present - even without Section Headers!

  1. 在IB中,使用两个按钮创建一个UIVC,一个按钮位于左上方,另一个按钮位于右上方.

  1. In IB, create a UIVC with two buttons, one top left, the other top right.

从资产目录中拖动UITVC并将其放在原始VC的一侧,然后从资产库中拖动UIVC并将其放在另一侧.

Drag a UITVC from the Asset Catalog and place it on one side of the original VC, then drag a UIVC from the Asset Library and put that on the other side.

将UITableView从资源库中拖到新" UIViewController上,然后将其顶部和底部设置为指南安全区域布局,将其左侧和右侧分别设置为0常数(可以保留默认值20-没有区别).

Drag a UITableView from the Asset Library onto the 'new' UIViewController and just set it's top and bottom to the guide safe area layouts and the left and right to the safe margins with a 0 constant (you can keep the default 20 - makes no difference).

现在,将这些按钮连接到原始UIVC,以便按每个按钮实例化一个或另外两个控制器,并在弹出窗口中显示它们.

Now, wire up those buttons to the original UIVC so that pressing each instantiates one or the other two controllers, and displays them in a popover.

注意,任何UIViewController上都没有格式设置,样式,也没有任何默认IB设置的更改.

Notice, there is no formatting, no styling, no changing of ANY default IB settings on any of the UIViewControllers.

这是中心" VC代码:

Here's the 'centre' VC code:

import UIKit



class ViewController: UIViewController, UIPopoverPresentationControllerDelegate
{
    @IBOutlet weak var tbutton: UIButton!
    @IBOutlet weak var button: UIButton!



    @IBAction func buttonTouched(_ sender: UIButton)
    {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let libraryVC = storyboard.instantiateViewController(withIdentifier: "library")

        libraryVC.modalPresentationStyle = .popover

        if let popover = libraryVC.popoverPresentationController
        {
            popover.sourceView = self.button
            popover.sourceRect = self.button.bounds

            popover.delegate = self
        }

        libraryVC.preferredContentSize = CGSize(width: 400, height: 2048)

        libraryVC.view.layer.borderColor  = UIColor.white.cgColor
        libraryVC.view.layer.borderWidth  = 5.0
        libraryVC.view.layer.cornerRadius = 16.0

        self.present(libraryVC, animated: true)

    }



    @IBAction func tbuttonTouched(_ sender: UIButton)
    {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let libraryVC = storyboard.instantiateViewController(withIdentifier: "tlibrary")

        libraryVC.modalPresentationStyle = .popover

        if let popover = libraryVC.popoverPresentationController
        {
            popover.sourceView = self.tbutton
            popover.sourceRect = self.tbutton.bounds

            popover.delegate = self
        }

        libraryVC.preferredContentSize = CGSize(width: 400, height: 2048)

        libraryVC.view.layer.borderColor  = UIColor.white.cgColor
        libraryVC.view.layer.borderWidth  = 5.0
        libraryVC.view.layer.cornerRadius = 16.0

        self.present(libraryVC, animated: true)
    }



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

这是IB中的布局-请注意,我对所有视图的背景颜色进行了不同的更改,以便您可以查看引起问题的视图.

Here's the layout in IB - note that I've changed the background colours on all the views differently so you can see what views are causing problems.

这是来自各个侧面VC的代码:

And here is the code from each of the side VC's:


import UIKit



class LibraryViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
{
    @IBOutlet weak var table: UITableView!



    override func viewDidLoad()
    {

    }



    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        12
    }



    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath) as? MyTableViewCell else
        {
            fatalError("expected to dequeue MenuItemTableCell - check storyboard")
        }

        return cell
    }
}

和另一个:

import UIKit



class LibraryTableViewController: UITableViewController
{
    override func viewDidLoad()
    {
        super.viewDidLoad()

        self.tableView.delegate = self
        self.tableView.dataSource = self
    }



    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }



    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        // #warning Incomplete implementation, return the number of rows
        return 10
    }



    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath) as? MyTableViewCell else
        {
            fatalError("expected to dequeue MenuItemTableCell - check storyboard")
        }

        return cell
    }
}

这是IB配置:

结果如下:

推荐答案

我找到了答案.我必须实现自己的UIPopoverBackgroundView. 示例: https://github. com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch09p476popovers/ch22p751popovers/MyPopoverBackgroundView.swift 它对我有用.我的弹出窗口

I have found the answer. I have to implement my own UIPopoverBackgroundView. Example: https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch09p476popovers/ch22p751popovers/MyPopoverBackgroundView.swift It works for me.my popover

这篇关于ios13 UIPopoverViewController显示UITableViewController-安全区域问题/表的缺失部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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