我想管理内存,所以我想在退出ViewController时退出UIview。
而我尝试使用关键字“弱”,我因为我的聊天键盘为零而崩溃。
我不知道为什么使它崩溃。
谢谢。
为什么我用uift初始化uiview和uiview呢?
class ChatKeyboard: UIView {
var buttonMic:UIButton = {()->UIButton in
let ui:UIButton = GeneratorButton()
return ui
}()
override init(frame: CGRect) {
super.init(frame: frame)
print("===) ChatKeyboard init.")
translatesAutoresizingMaskIntoConstraints = false
loadContent()
loadConstrain()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
deinit {
print("===) ChatKeyboard deinit.")
}
func loadContent() {
backgroundColor = UIColor.white
addSubview(buttonMic)
}
func loadConstrain() {
buttonMic.snp.makeConstraints { (make) -> Void in
make.left.equalTo(micLeftPadding)
make.top.equalTo(micTopPadding)
make.width.equalTo(UIScreen.main.bounds.width*0.0581)
make.height.equalTo(UIScreen.main.bounds.height*0.045)
}
}
}
class ChatroomViewController: UIViewController{
weak var chatKeyboard:ChatKeyboard?
override func viewDidLoad() {
super.viewDidLoad()
chatKeyboard = ChatKeyboard(frame: CGRect(x: 0, y: 0, width: 300, height: 44))
}
}
我在设置断点 “chatKeyboard = ChatKeyboard(:的CGRect(X:帧0,Y:0,宽度:300,高度:44))”,然后我的日志打印:
===) ChatKeyboard init.
===) ChatKeyboard deinit.