我想管理內存,所以我想在退出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.