【发布时间】:2015-01-28 15:39:33
【问题描述】:
这是我的类,带有覆盖初始化
class BottomView: UIView {
// MARK: - initilization
override init() {
println("init")
super.init()
setup()
}
override init(frame: CGRect) {
println("init frame")
super.init(frame: frame)
setup()
}
required init(coder aDecoder: NSCoder) {
println("init decoder")
super.init(coder: aDecoder)
setup()
}
func setup() {
println("setup")
}
}
然后我用下面的代码在我的 ViewController 中初始化
class ViewController: UIViewController {
let bottomView = BottomView()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
bottomView.frame = CGRectMake(0.0, self.view.frame.height/2.0, self.view.frame.width, self.view.frame.height/2.0)
bottomView.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleTopMargin
self.view.addSubview(bottomView)
}
}
我的输出是
init
init frame
setup
setup
所以我的问题是,为什么会调用 init(frame:) ?
【问题讨论】:
标签: ios iphone ipad swift init