ios - UIPopoverBackgroundView contentViewInsets 必须由子类实现

标签 ios swift uipopoverbackgroundview

我正在实现自定义 PopoverBackgroundView,并按照 Swift documentation 中的说明进行操作我必须实现如下方法:

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 must be implemented by subclassers.

对于这个子类,Apple 似乎有一些乱码异常,as can be seen here ,因为我确实实现了 contentViewInsets,但仍然出现错误。

这就是我在 prepareForSegue 方法中将背景类设置为弹出框的方式:

popover.popoverBackgroundViewClass = SettingsPopoverBackgroundView.self

是吗?

谁能看出我做错了什么?

最佳答案

contentViewInsets()arrowBase()arrowHeight()都是类函数,所以需要在前面加上“override class” func 的那些。

对于 arrowOffsetarrowDirection,文档说您的方法不能调用 super。我不确定您到底需要在这些 setter 中放入什么(这取决于您要做什么),但是如果您将它们留空,应用程序应该可以正常运行(尽管您不会看到箭头).

关于ios - UIPopoverBackgroundView contentViewInsets 必须由子类实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29459668/

相关文章:

ios - 从 iOS 应用程序调用服务器上的函数 - Objective C

iphone - ABAddressBookSave 随机崩溃

html - 使用 Kanna 快速解析 html 时获取特殊的 div 类数据

ios - 更改 UIPopoverView 背景 + 箭头颜色

ios - 日期选择器 - 显示两个日期之间的时间 (UIDatePickerModeDateAndTime)

ios - 无法使用免费的苹果开发者帐户下载配置文件

ios - 如何在 Swift 中的 collectionView 中显示每个类别的多个类别?

ios - Swift 2.1 - 制作宽度相对于文本长度的动态按钮

ios - 没有圆角的 UIPopoverBackgroundView

ios - UISplitViewController 一致分隔线