【发布时间】:2020-01-28 16:25:09
【问题描述】:
与本帖主题相同:
iOS 13 - UIPopoverPresentationController sourceview content visible in the arrow
我有一个从 Storyboard 实例化的 UITableViewController。我在 UIPopoverViewController 中展示它。
根据方向,我要么缺少一侧,要么缺少顶部,_UITableViewHeaderFooterViewBackground 的内容会“通过”箭头滚动。
怎么了:
这些是它在顶部的时候,但如果它出现在侧面,那么整个侧面
编辑:我正在使用安全区域指南:
正如我之前所说,我从对象库中拖出一个全新的 UITVC,然后将原型单元更改为我的应用程序的要求。
我对任何安全区域的切换或设置进行了零更改。
我不会更改代码中的任何安全区域插入或调整。
所以,谢谢@Alex,但这不是问题,或者如果是,我不知道该怎么办。
编辑 2:
今天下午,我确保我的课程中有零代码,用于执行任何格式、颜色、插入或任何与更改默认表格单元格的任何形式有关的任何事情。
然后我在 IB 中完全删除了我的 UITVC 并创建了一个新的,创建没有样式的新原型单元格,除了在单元格中放置一个 UIImageView。
我确保 UITVC、tableviewcell 和内容视图都在 IB 中勾选了“安全区域”和“安全边距”。
重建应用程序并运行。
完全一样。
我仍然有内容和背景在箭头上,如果我在表格周围添加一个边框,则呈现侧被“切断”。
编辑 3:
我知道问题出在哪里!!!
是 _UITableViewHeaderFooterViewBackground 不能很好地与 AutoLayout 配合使用!!
我不确定如何解决它,但这就是问题所在。
编辑 4 / 更新:
今天我构建了以下应用程序,但错误仍然存在 - 即使没有节标题!
在 IB 中,创建一个带有两个按钮的 UIVC,一个左上角,另一个右上角。
从 Asset Catalog 中拖动一个 UIVC 并将其放置在原始 VC 的一侧,然后从 Asset Library 中拖动一个 UIVC 并将其放置在另一侧。
将 UITableView 从 Asset Library 拖到“新”UIViewController 上,只需将其顶部和底部设置为引导安全区域布局,并将左侧和右侧设置为安全边距,常量为 0(您可以保留默认 20 - 没有区别)。
现在,将这些按钮连接到原始 UIVC,以便按下每个按钮实例化一个或其他两个控制器,并在弹出窗口中显示它们。
注意,没有任何格式,没有样式,没有更改任何 UIViewController 上的任何默认 IB 设置。
这是“中心”VC 代码:
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 中的布局 - 请注意,我已经以不同方式更改了所有视图的背景颜色,以便您可以看到哪些视图导致了问题。
这里是来自每一方 VC 的代码:
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 配置:
【问题讨论】:
-
您不应该尝试在
UITableViewController中设置表格视图的约束。它已经被设置为做正确的事情。 -
确保只在
contentView的表格单元格中添加内容。 -
@rmaddy 好的,但这与我链接到的堆栈帖子中的 cmets 中的“建议”相矛盾。如果我什么都不做,那么我会从上面得到图像,但没有冲突的约束警告。
-
iOS 13 故意更改了内容在弹出窗口中的显示方式,因此默认情况下内容确实显示在箭头中。使用安全区域将东西保存在弹出框的非箭头部分内。对于表格视图,除了确保将单元格子视图放入单元格的 contentView 之外,别无他法。而且您的实际问题尚不清楚。图片根本没有显示您的问题所在。而且您还没有为您的表格视图显示任何相关代码。
-
我在 UITableView 中没有任何“相关”代码,因为除了显示与数据相关的行之外,我没有在表视图中执行任何操作,就像在其他所有表中一样。在“安全区域”或“缩进”等方面没有任何具体或独特之处......也许你可以展示一些“正确”的代码或实现,我可以检查一下?
标签: swift uitableview uipopovercontroller ios13 safearealayoutguide