我遵循这个帖子来实现一个UIPopoverBackgroundView。我检查了UIPopoverBackgroundView类,我认为我已经实现了所有必需的函数和变量,但是在运行时错误仍然存在。
由于“NSInternalInconsistencyException”异常终止应用程序,原因:'-UIPopoverBackgroundView :必须由subclassers.‘实现。’
import UIKit
class CustomPopoverBackground: UIPopoverBackgroundView {
override func layoutSubviews() {
super.layoutSubviews()
}
override var arrowOffset: CGFloat {
get {
return 0.0
}
set {
super.arrowOffset = newValue
}
}
override var arrowDirection: UIPopoverArrowDirection {
get {
return UIPopoverArrowDirection.Up
}
set {
super.arrowDirection = newValue
}
}
override class func contentViewInsets() -> UIEdgeInsets {
return UIEdgeInsetsMake(10, 10, 10, 10)
}
override class func arrowBase() -> CGFloat {
return 2.0
}
override class func arrowHeight() -> CGFloat {
return 2.0
}
}我哪里错了?什么是setArrowOffset,我在UIPopoverBackgroundView或UIPopoverBackgroundViewMethods协议类中没有找到它。
发布于 2016-06-05 05:40:30
另一个博客帖子,它实际上显示了自定义UIPopOverBackgroundView的实现
它将箭头保存在一个结构中
private struct Arrow {
let height : CGFloat = 30.0
let base : CGFloat = 20.0
var direction : Direction = .UP
var offset : CGFloat = 0.0
}
override var arrowOffset: CGFloat {
get {
return arrow.offset
}
set {
arrow.offset = newValue
}
}这里没有超级调用,该类期望子类实际保存值,而不使用超类实现。
https://stackoverflow.com/questions/37638392
复制相似问题