UIPopoverBackgroundView contentViewInsets必须由subclassers实现
我正在实现一个自定义的PopoverBackgroundView,并且按照Swift文档中的说明,我必须实现如下的方法:
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必须由subclassers实现。
看起来像苹果有一些乱码的例外,因为这里可以看到 ,因为我实现contentViewInsets,但仍然得到错误。
这就是我如何设置prepareForSegue方法中popover的背景类:
popover.popoverBackgroundViewClass = SettingsPopoverBackgroundView.self
这样对吗?
任何人都可以看到我做错了什么?
contentViewInsets()
, arrowBase()
和arrowHeight()
都是类的函数,所以你需要在func
前面覆盖类。
对于arrowOffset
和arrowDirection
,文档说你的方法不能调用super 。 我不确定你需要在这些设置器中放置什么(这取决于你正在做什么),但是如果你把它们留空,应用程序应该运行没有错误(尽pipe你不会看到一个箭头)。