我正在实现一个自定义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必须由子类实现。
对于这个子类从这里可以看到,苹果似乎有一些混乱的异常,因为我确实实现了contentViewInsets,但仍然会出现错误。
以下是如何将背景类设置为prepareForSegue方法中的弹出程序:
popover.popoverBackgroundViewClass = SettingsPopoverBackgroundView.self是对的吗?
有人能看到我做错了什么吗?
发布于 2015-04-05 20:20:43
contentViewInsets()、arrowBase()和arrowHeight()都是类函数,因此需要在func前面“覆盖类”。
对于arrowOffset和arrowDirection,文档说您的方法不能调用超级。我不确定您需要在这些设置器中添加什么(这取决于您想要做什么),但是如果您将其保留为空白,则应用程序运行时应该没有错误(尽管您不会看到箭头)。
https://stackoverflow.com/questions/29459668
复制相似问题