这是我的uiview类:
class overlap: UIView{
init() {
super.init(frame: UIScreen.main.bounds)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
fatalError("init(coder:) has not been implemented")
}
}
它应该填满屏幕。当我在故事板中添加视图并限制在屏幕边缘上的约束时,启动应用程序时会崩溃。该错误如上所述。
创建和添加子类以编程方式使用此初始化功能:
override init(frame: CGRect) {
super.init(frame: frame)
}
,但我希望它可以通过故事板重复使用,而无需添加代码。我的代码有什么问题,甚至可能是我想要的?
谢谢!
我启动应用程序时崩溃
因为这是您的代码告诉它要做的。
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
fatalError("init(coder:) has not been implemented")
}
fatalError
表示"崩溃我"。