将子类添加到故事板崩溃

这是我的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") } } 

它应该只填满屏幕。 当我将故事板中的视图添加到固定在屏幕边缘的约束中时,它会在我启动应用程序时崩溃。 错误出现在上面的代码中。

用这个init函数编程创build和添加子类:

 override init(frame: CGRect) { super.init(frame: frame) } 

但是我希望它可以通过Storyboard重用,而不需要添加代码。 我的代码有什么问题,甚至可能是我想要的?

谢谢!

它在我启动应用程序时崩溃

因为这是你的代码告诉它做的。

 required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) fatalError("init(coder:) has not been implemented") } 

fatalError意思是“撞我”。