如何更改箭头指向的位置以及tableview单元格内弹出窗口的位置?
继承人到目前为止我所拥有的
else if segue.identifier == "openingHours" {
let vc = segue.destinationViewController
vc.preferredContentSize = CGSize(width: 200, height: 100)
let controller = vc.popoverPresentationController
if controller != nil {
controller?.delegate = self
}
}
如您所见,弹出框出现在单元格的顶角。我希望popover显示在包含文本“Arrow from below”的蓝色视图下方,箭头指向视图
答案 0 :(得分:0)
答案 1 :(得分:0)
这太晚了。但是,如果有人偶然发现了这个问题:
它基于以编程方式设置UIPopoverController
的锚点。如果您使用情节提要,您仍然需要将其分配给情节提要中的某个内容(例如“视图”),但是代码将覆盖该选择。
这可以通过将以下内容应用于您的prepare(for: sender:)
并在UIPopoverController
的发件人参数中添加performSegue(withIdentifier: , sender:)
锚定的所需视图来简单地实现。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
else if segue.identifier == "openingHours" {
let vc = segue.destinationViewController
vc.preferredContentSize = CGSize(width: 200, height: 100)
vc?.popoverPresentationController?.delegate = self
// Remember to pass in the cell or whatever view you want it to be anchored to in performSegue(withIdentifier: "YourSegueID", sender: tableViewCell)
if let anchorView = sender as? UIView {
vc?.popoverPresentationController?.sourceView = anchorView
}
// If you want to anchor it to a UIBarButtonItem (in a nav bar for example use this), remove the code bellow if you are using a view:
else if let anchorView = sender as? UIBarButtonItem {
vc?.popoverPresentationController?.barButtonItem = anchorView
}
}
}