OC与Swift混编时,创建一个swift类继承自OC类,由于这个OC类已自定义构造函数,所以在这个swift类中重写父类的init构造函数初始化子控件,但是在运行时报错:
fatal error: use of unimplemented initializer 'init(frame:)' for class 'Arrietty.XYCustomAnnotationView'
解决方法:在这个swift类中重新 init(frame: CGRect),并实现super方法即可
// MARK: - Life Cycle
override init!(annotation: MAAnnotation!, reuseIdentifier: String!) {
super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)
self.bounds = CGRect(x: 0.0, y: 0.0, width: kWidth, height: kHeight)
self.backgroundColor = UIColor.clear
self.addSubview(backgroundImageView)
self.backgroundImageView.frame = CGRect(x: kHoriMargin, y: kVertMargin, width: kPortraitWidth, height: kPortraitWidth)
/* 创建iconView展示用户头像 */
self.backgroundImageView.addSubview(iconView)
iconView.frame = CGRect(x: kHoriMargin, y: kVertMargin, width: kPortraitWidth, height: kPortraitWidth)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override init(frame: CGRect) {
super.init(frame: frame)
}