我想知道是否有一种方法可以删除UIPopoverPresentationController的左右边距:

我尝试这样做:
suggestionsTableViewController.popoverPresentationController?.popoverLayoutMargins = UIEdgeInsets(top: -10, left: -10, bottom: -10, right: -10)但一切都没有改变。
我也尝试使用UIPopoverBackgroundView:
suggestionsTableViewController.popoverPresentationController?.popoverBackgroundViewClass = HUBBPopoverBackgroundView.self这是我的UIPopoverBackgroundView的代码:
class HUBBPopoverBackgroundView: UIPopoverBackgroundView {
override func layoutSubviews() {
super.layoutSubviews()
}
public override static func contentViewInsets() -> UIEdgeInsets {
return UIEdgeInsets(top: -10, left: -10, bottom: -10, right: -10)
}
public override static func arrowBase() -> CGFloat {
return 2.0
}
public override static func arrowHeight() -> CGFloat {
return 2.0
}
override var arrowOffset: CGFloat {
get {
return self.arrowOffset
}
set {
self.arrowOffset = newValue
}
}
override var arrowDirection: UIPopoverArrowDirection {
get {
return self.arrowDirection
}
set {
self.arrowDirection = newValue
}
}
}你能帮我吗??
谢谢。
发布于 2017-04-01 21:15:20
不幸的是,popoverLayoutMargins现在什么都不做;它曾经工作过,但它停止了。您可以使用弹出式鼠标悬停的preferredContentSize来指定弹出式鼠标悬停的宽度,但不能指定弹出式鼠标的确切位置。
如果你想要这样的控件,不要使用弹出窗口,而是使用一个自定义的控制器。使用UIPresentationController子类,您可以完全控制所呈现的视图控制器的位置。
发布于 2019-03-27 05:51:06
覆盖contentViewInsets以弥补默认边距的子类UIPopoverBackgroundView。(注意:必须覆盖UIPopoverBackgroundView的所有变量和函数,子类才能工作。根据需要对其进行配置。)
class NoMarginsPopoverBackgroundView: UIPopoverBackgroundView {
override var arrowOffset: CGFloat
{
get { return 0.0 }
set { }
}
override var arrowDirection: UIPopoverArrowDirection
{
get { return [] }
set { }
}
override class func contentViewInsets() -> UIEdgeInsets {
return UIEdgeInsets(top: -10, left: -10, bottom: -10, right: -10)
}
override class func arrowBase() -> CGFloat {
return 0.0
}
override class func arrowHeight() -> CGFloat {
return 0.0
}
}然后,将UIPopoverPresentationController popoverBackgroundViewClass属性分配给子类。
popoverPresentationController?.popoverBackgroundViewClass = NoMarginsPopoverBackgroundView.selfhttps://stackoverflow.com/questions/43156924
复制相似问题