我正在实现自定义 PopoverBackgroundView,并按照 Swift documentation 中的说明进行操作我必须实现如下方法:
class SettingsPopoverBackgroundView: UIPopoverBackgroundView {
override var arrowOffset: CGFloat {
get {
return 0.0
}
set {
super.arrowOffset = newValue
}
}
override var arrowDirection: UIPopoverArrowDirection {
get {
return UIPopoverArrowDirection.Up
}
set {
super.arrowDirection = newValue
}
}
func contentViewInsets() -> UIEdgeInsets {
return UIEdgeInsetsMake(10, 10, 10, 10)
}
func arrowBase() -> CGFloat {
return 2.0
}
func arrowHeight() -> CGFloat {
return 2.0
}
}
但是,我仍然收到错误:
UIPopoverBackgroundView contentViewInsets must be implemented by subclassers.
对于这个子类,Apple 似乎有一些乱码异常,as can be seen here ,因为我确实实现了 contentViewInsets,但仍然出现错误。
这就是我在 prepareForSegue 方法中将背景类设置为弹出框的方式:
popover.popoverBackgroundViewClass = SettingsPopoverBackgroundView.self
是吗?
谁能看出我做错了什么?
最佳答案
contentViewInsets()
、arrowBase()
、arrowHeight()
都是类函数,所以需要在前面加上“override class” func
的那些。
对于 arrowOffset
和 arrowDirection
,文档说您的方法不能调用 super。我不确定您到底需要在这些 setter 中放入什么(这取决于您要做什么),但是如果您将它们留空,应用程序应该可以正常运行(尽管您不会看到箭头).
关于ios - UIPopoverBackgroundView contentViewInsets 必须由子类实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29459668/