and*_*osr 6 ios uipopoverbackgroundview swift
我正在实现一个自定义的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)
这样对吗?
任何人都可以看到我做错了什么?
contentViewInsets(),arrowBase()并且arrowHeight()都是类函数,因此您需要在前面使用"覆盖类" func.
对于arrowOffset和arrowDirection,文档说你的方法不能称为super.我不确定你需要在那些装置中放置什么(这取决于你想要做什么),但是如果你把它们留空,应用程序应该没有错误地运行(尽管你不会看到箭头).