我正在实现一个自定义的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
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我仍然收到错误:
UIPopoverBackgroundView contentViewInsets必须由子类实现.
对于这个子类化,似乎Apple有一些乱码异常,这里可以看到,因为我确实实现了contentViewInsets,但仍然得到了错误.
这就是我在prepareForSegue方法中将后台类设置为popover的方法:
popover.popoverBackgroundViewClass = SettingsPopoverBackgroundView.self
Run Code Online (Sandbox Code Playgroud)
这样对吗? …